Database Problem ?
-
I have the following code that I am compiling into an assembly, it compiles fine and when I debug and step through it my
i
variable is always 0, however when I run the same query in SQL Query Analyzer I get a value of 1130, does anyone have any ideas as to what I am doing wrong here?int mcpp::MyNumber::GetWebStat()
{
SqlConnection* mySQLConnection;
SqlCommand* sqlCommand;
SqlDataReader* dr;
String* sql;
int i;
try
{
sql = "select count(*) as myCount from site_stats";
mySQLConnection = new SqlConnection(S"server=Nick;database=DeveloperNotes;Integrated Security=yes;");
mySQLConnection->Open ();sqlCommand = new SqlCommand(sql, mySQLConnection); dr = sqlCommand->ExecuteReader(); i = Convert::ToInt32(dr->Item\["myCount"\]); return i; } catch(Exception\* e) { Console::Write(e->ToString()); } \_\_finally { mySQLConnection->Close(); }
}
Nick Parker
May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
-
I have the following code that I am compiling into an assembly, it compiles fine and when I debug and step through it my
i
variable is always 0, however when I run the same query in SQL Query Analyzer I get a value of 1130, does anyone have any ideas as to what I am doing wrong here?int mcpp::MyNumber::GetWebStat()
{
SqlConnection* mySQLConnection;
SqlCommand* sqlCommand;
SqlDataReader* dr;
String* sql;
int i;
try
{
sql = "select count(*) as myCount from site_stats";
mySQLConnection = new SqlConnection(S"server=Nick;database=DeveloperNotes;Integrated Security=yes;");
mySQLConnection->Open ();sqlCommand = new SqlCommand(sql, mySQLConnection); dr = sqlCommand->ExecuteReader(); i = Convert::ToInt32(dr->Item\["myCount"\]); return i; } catch(Exception\* e) { Console::Write(e->ToString()); } \_\_finally { mySQLConnection->Close(); }
}
Nick Parker
May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
Did you try the same program with C#, just making sure that there is no logical errors. Cheers Kannan
-
Did you try the same program with C#, just making sure that there is no logical errors. Cheers Kannan
Kannan Kalyanaraman wrote: Did you try the same program with C#, just making sure that there is no logical errors. Good idea, I am not sure and will check when I get home. :)
Nick Parker
-
I have the following code that I am compiling into an assembly, it compiles fine and when I debug and step through it my
i
variable is always 0, however when I run the same query in SQL Query Analyzer I get a value of 1130, does anyone have any ideas as to what I am doing wrong here?int mcpp::MyNumber::GetWebStat()
{
SqlConnection* mySQLConnection;
SqlCommand* sqlCommand;
SqlDataReader* dr;
String* sql;
int i;
try
{
sql = "select count(*) as myCount from site_stats";
mySQLConnection = new SqlConnection(S"server=Nick;database=DeveloperNotes;Integrated Security=yes;");
mySQLConnection->Open ();sqlCommand = new SqlCommand(sql, mySQLConnection); dr = sqlCommand->ExecuteReader(); i = Convert::ToInt32(dr->Item\["myCount"\]); return i; } catch(Exception\* e) { Console::Write(e->ToString()); } \_\_finally { mySQLConnection->Close(); }
}
Nick Parker
May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
-
Until u say Reader->Read(), the pointer will not go to the first record so that's the reason u are getting 0. try this while(Reader->Read) { // your code. }
Thank you, that was exactly what I needed. :)
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein