problem whit datareader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • virtuoso
    New Member
    • May 2010
    • 10

    problem whit datareader

    I have a prpblem with the following code ( a sketch of it); cmd works fine but cmd2 not; Whit query2 I want to extract a value form database but even if the value exist the " if (dr.HasRows) " pass it and go to "else {//}". I hope you will understand what I'm trying to say.

    Code:
    string query ="select..."
    string query2 = "select..."
     MySqlCommand cmd = new MySqlCommand(query, connection);
     MySqlCommand cmd2 = new MySqlCommand(query2, connection);
    MySqlDataReader dr;
    dr = cmd.ExecuteReader();
                    int i;
                    if (dr.HasRows)
                    {i = 1;
                        while (dr.Read())
                        {..}
                    }
                   else
                    {i = 2; }
                    dr.Close();
    
                   if (i == 1)
                    {...
                     dr = cmd2.ExecuteReader();
                     if (dr.HasRows)                     // here
                        {
                          while (dr.Read())
                            { ...}
                        }
                     else {//}
                    }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    It helps the volunteers here tremendously when you post the actual code that is causing you problems. Not the entire application. Just the parts you have written that are causing the problem.

    1 - Copy the code from Visual Studio
    [imgnothumb]http://clint.stlaurent .net/bytes/code-copy.jpg[/imgnothumb]

    2 - In your question thread, click the [code] tags button. Its the one that looks like # symbol
    [imgnothumb]http://clint.stlaurent .net/bytes/tags-code.jpg[/imgnothumb]
    Code tags have magically appeared in your post with the cursor right between them.

    [code]|[/code]

    Just paste and you should see this
    [CODE] public void BrokenMethod()
    {
    // I don't understand why this doesn't work
    int Yogi = "Bear";
    }[/CODE]

    Which will look like this
    Code:
            public void BrokenMethod()
            {
                // I don't understand why this doesn't work
                int Yogi = "Bear";
            }
    More on tags. They're cool. Check'em out.

    Comment

    • virtuoso
      New Member
      • May 2010
      • 10

      #3
      this is exactly what i did :) and in the begining I specified what part dont't work; that part alone is irelevant;

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I don't think so.

        For one: {...} won't compile

        Two: I doubt this works
        Code:
        string query ="select...";
        but I could be wrong as I don't do much SQL

        Comment

        • virtuoso
          New Member
          • May 2010
          • 10

          #5
          Originally posted by tlhintoq
          I don't think so.

          For one: {...} won't compile

          Two: I doubt this works
          Code:
          string query ="select...";
          but I could be wrong as I don't do much SQL
          As I said, it's only a sketch; Inste of "..." is a large code that is irrelevant to my problem so I put "..." insted of it; I put only the code that count, that can cause my problem;

          Comment

          Working...