|
Do not cross post.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
That was deleted as i posted in wrong forum.
|
|
|
|
|
I think I have already suggested one link to do this.
|
|
|
|
|
Thanx Abhishek Sur
modified on Friday, November 20, 2009 10:44 AM
|
|
|
|
|
Hi abhishek,
I also need to format my excel sheet as follows:
the data has different values in 5 columns for the same values in the first 10 columns.
I need to show the columns with same data only once and then just populate the columns whuich have different data for the same value in first 10 columns.
|
|
|
|
|
FEMDEV wrote: I need to show the columns with same data only once and then just populate the columns whuich have different data for the same value in first 10 columns.
I am totally stumped.... I am confused. Please let me clear this a bit.
|
|
|
|
|
Good Day All
i have the Following Function
private static void OMEGA_calcActvEqv()
{
SqlConnection conn1 = CommonFunctions.getSQLConnectionForThread(THREAD_DATA[0].ToString());
string SQL = "SELECT MAX(D.OFFS + 1) * MAX(R.OFFS + 1) FROM TBL_ROWS R, TBL_CLMN D; SELECT MAX(OFFS + 1) FROM TBL_ROWS;";
SqlCommand cmd = new SqlCommand(SQL, conn1);
SqlDataReader rdr = cmd.ExecuteReader();
int size = 0;
if (rdr.Read())
{
size = Convert.ToInt32(rdr[0]);
}
int maxPeriods = 0;
if (rdr.NextResult())
{
if (rdr.Read())
{
maxPeriods = Convert.ToInt32(rdr[0]);
}
}
rdr.Close();
SQL = "SELECT MEA.EQV [EQV], MEA.ACTV [ACTV] FROM MTM_EQV_ACTV MEA ORDER BY MEA.EQV, MEA.ACTV ";
if ((THREAD_DATA.Length > 3) && (THREAD_DATA[3] != null))
{
string EQV = CommonFunctions.ExecuteScalarInThread("SELECT MEA.EQV FROM MTM_EQV_ACTV MEA WHERE ACTV=" + THREAD_DATA[3], conn1).ToString();
SQL = "SELECT MEA.EQV [EQV], MEA.ACTV [ACTV] FROM MTM_EQV_ACTV MEA WHERE EQV='" + EQV + "' ORDER BY MEA.EQV, MEA.ACTV ";
}
cmd = new SqlCommand(SQL, conn1);
rdr = cmd.ExecuteReader();
string eqvSet = string.Empty;
List<int> actvs = new List<int>();
while (rdr.Read())
{
if (eqvSet != rdr["EQV"].ToString())
{
if (actvs.Count > 1)
{
OMEGA_intersectDomns(actvs, size, maxPeriods);
}
actvs.Clear();
eqvSet = rdr["EQV"].ToString();
if (!DBNull.Value.Equals(rdr["ACTV"]))
{
actvs.Add(Convert.ToInt32(rdr["ACTV"]));
}
}
else
{
if (!DBNull.Value.Equals(rdr["ACTV"]))
{
actvs.Add(Convert.ToInt32(rdr["ACTV"]));
}
}
}
rdr.Close();
if (actvs.Count > 1)
{
OMEGA_intersectDomns(actvs, size, maxPeriods);
actvs.Clear();
}
conn1.Close();
conn1.Dispose();
}
and the Definition of function ExecuteScalarInThread
is
public static object ExecuteScalarInThread(string sql, SqlConnection conn1)
{
SqlCommand sqlcommand = new SqlCommand(sql, conn1);
sqlcommand.CommandType = CommandType.Text;
object ret = new object();
if (conn1.State != ConnectionState.Open)
{
conn1.Open();
}
try
{
ret = sqlcommand.ExecuteScalar();
}
catch (Exception e)
{
ret = e.Message;
}
conn1.Close();
return ret;
}
i get an Error in the bolded line of the Function OMEGA_calcActvEqv() on this line
rdr = cmd.ExecuteReader();
that says
ExecuteReader requires an open and available Connection. The connection's current state is closed.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
You are closing the connection inside ExecuteScalarInThread method. That should be the problem.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thank you very much. i had a LongDay.
that solved my Problem i can go home now
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Vuyiswa Maseko wrote: Thank you very much. i had a LongDay.
that solved my Problem i can go home now
Then you should mark that post as helful.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
How by Voting for it ? i have already done that. or did i miss something
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Vuyiswa Maseko wrote: or did i miss something
No !
Your are done !
Thanks !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Enjoy your evening.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
OK, you didn't open the connection before you tried to Execute the Reader. So, put a line in before the ExecuteReader to open the conn1 connection object.
conn1.Open();
|
|
|
|
|
hi Dave long time. I have a Function that opens the Connection. This is Where i open the connection
<br />
SqlConnection conn1 = CommonFunctions.getSQLConnectionForThread(THREAD_DATA[0].ToString());
but now my mistake was that in another function i closed this Global Connection and it gave a problem when i tried to execute the reader again later. So d@nish saw it and pointed it out.
Thanks Dave
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Yeah, what they said.
You should go further and Open the Connection before each use and Close it afterward (preferably in a finally).
You can also check the Connection's State and Open it if needed -- that's what I do.
(Working with DataReaders makes this a little more difficult because you have to hold the Connection open and remember to Close it later.)
|
|
|
|
|
You are Right. i have Opened the Connection. i have a Global Connection Module. And when it moved to another Function that function closed that Connection. So that where was the the Problem. By Commenting that part it worked.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I am collecting OS info using Win32_OperatingSystem(WMI).
its one property(InstallDate) which gives Installation Date of the OS, but datetime is in 20091117110355.375000+330 format. I want to convert this into actual DateTime format.
Thanks,
Sunil G.
|
|
|
|
|
Try this...
DateTime GetMeTheDateAndTime(string s)
{
return DateTime.ParseExact(s.Substring(0, 14), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvarientCulture);
}
...you may wan't to apply some validation thou
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
|
This works for sure, there may be something more compact:
string s="20091117110355.375000+330";
DateTime.ParseExact(s.Substring(0,14), "yyyyMMddHHmmss",null);
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi,
There is also a .NET class to handle this conversion.
string dmtfDate = "20091117110355.375000+330";
DateTime dt = System.Management.ManagementDateTimeConverter.ToDateTime(dmtfDate);
Alan.
|
|
|
|
|
Hi ALL,
I am dynamically adding items to a combobox using a text box and a button. The value gets populated into the combobox, but when I close the form and reopen it, the combobox has no values in it.
Is there any way in which i can view the added item after closing and reopening the form.
Thanks,
|
|
|
|
|
You could create a static list which is also added to when you add to the comboBox, then use this list to populate the comboBox when the form is opened... FormShown event or something similar will do the trick
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
1???
What's wrong with my suggestion?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|