data reader not getting refreshed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bssajeev
    New Member
    • Feb 2013
    • 2

    data reader not getting refreshed

    Here is a brief account of the problem

    Sql_data_connec tion is the dataconnection to my mysql database
    QueryString is sql statement as given below

    Code:
    QueryString = "select * from persmast where e_mail = " & "'" & UserName & "'"'
    (Username is an input string variable )
    All the above information I am passing to the code check_user as given below


    The problem is when I pass UserName for the first time in the procedure below the datareader finds the record (and fills the variables UserTLD and UserSign). But second time onwards when I call the same routine with the same QueryString the datareader returns nothing.

    Same difficulty I am finding with dataset also

    Please see what is wrong with the code below

    Code:
    Private Sub check_user()
    
    
            Using NewSqlConnection As New MySqlConnection(sql_data_connection)
    
                 Dim persmast_query As New MySqlCommand(QueryString, NewSqlConnection)
                
                NewSqlConnection.Open()
    
                Using PersmastReader As MySqlDataReader = persmast_query.ExecuteReader()
    
    
    
                    If PersmastReader.HasRows Then
    
             
       			While PersmastReader.Read
    
                            UserTLD = PersmastReader.GetString("tldno")
                            UserSign = PersmastReader.GetString("previlage")
                            TldNumber = UserTLD
                            UserValid = True
    
    
                        End While
    
                    Else
    
                      MsgBox("This user is not recogonised !!!", MsgBoxStyle.Critical, "Please Contact Administrator!!")
                
                    End If
                    PersmastReader.Close()
                    PersmastReader.Dispose()
                    
    
    
                End Using
    
                NewSqlConnection.Close()
                NewSqlConnection.Dispose()
                persmast_query.Dispose()
    
            End Using
    End sub
    Thanks in advance
    Last edited by zmbd; Feb 23 '13, 03:08 PM. Reason: [Meetee{Use code tags [/CODE] around code}][Z{Please use the <CODE/> formatting button to format your posted code and SQL}]
  • Mikkeee
    New Member
    • Feb 2013
    • 94

    #2
    It looks like you're not passing the querystring to your routine so it must be a public/private variable floating around. This makes me think that your issue could be where you're building your querystring. Are you resetting it everytime or somehow appending to it? Place a breakpoint on line 4 in your routine and output your querystring for both the first time you hit the routine and then on a subsequent call. My guess is that your querystring is bad.

    Side note here, inline sql isn't the best. You might want to look at using command parameters as your code is prone to SQL injection.

    Comment

    • bssajeev
      New Member
      • Feb 2013
      • 2

      #3
      Data reader probelm with my sql

      Thanks for your reply dear,
      I am passing the string (a Name) through a text box and first time it works fine. When the input is given through the same text box second time onwards the datareader returns null (even for the same Name). The text box input, the stored variable string, syntax everything I hvae checked and everthing is OK. The data reader is not getting refreshed for a second query..please help..

      Comment

      • Mikkeee
        New Member
        • Feb 2013
        • 94

        #4
        You say you checked everything and it's OK yet you're not getting the response you need. This tells me that everything is not OK. I would need to see the output of your querystring in your first call and a subsequent call to be able to help.

        Comment

        Working...