Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Database Problem ?

Database Problem ?

Scheduled Pinned Locked Moved Managed C++/CLI
databasesysadminsecuritydebugginghelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nick Parker
    wrote on last edited by
    #1

    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


    K T 2 Replies Last reply
    0
    • N 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


      K Offline
      K Offline
      Kannan Kalyanaraman
      wrote on last edited by
      #2

      Did you try the same program with C#, just making sure that there is no logical errors. Cheers Kannan

      N 1 Reply Last reply
      0
      • K Kannan Kalyanaraman

        Did you try the same program with C#, just making sure that there is no logical errors. Cheers Kannan

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • N 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


          T Offline
          T Offline
          taks
          wrote on last edited by
          #4

          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. }

          N 1 Reply Last reply
          0
          • T taks

            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. }

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups