By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

data reader not getting refreshed

P: 2
Here is a brief account of the problem

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

Expand|Select|Wrap|Line Numbers
  1. QueryString = "select * from persmast where e_mail = " & "'" & UserName & "'"'
  2. (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

Expand|Select|Wrap|Line Numbers
  1. Private Sub check_user()
  4.         Using NewSqlConnection As New MySqlConnection(sql_data_connection)
  6.              Dim persmast_query As New MySqlCommand(QueryString, NewSqlConnection)
  8.             NewSqlConnection.Open()
  10.             Using PersmastReader As MySqlDataReader = persmast_query.ExecuteReader()
  14.                 If PersmastReader.HasRows Then
  17.                While PersmastReader.Read
  19.                         UserTLD = PersmastReader.GetString("tldno")
  20.                         UserSign = PersmastReader.GetString("previlage")
  21.                         TldNumber = UserTLD
  22.                         UserValid = True
  25.                     End While
  27.                 Else
  29.                   MsgBox("This user is not recogonised !!!", MsgBoxStyle.Critical, "Please Contact Administrator!!")
  31.                 End If
  32.                 PersmastReader.Close()
  33.                 PersmastReader.Dispose()
  37.             End Using
  39.             NewSqlConnection.Close()
  40.             NewSqlConnection.Dispose()
  41.             persmast_query.Dispose()
  43.         End Using
  44. End sub
  45. Thanks in advance
Feb 21 '13 #1
Share this Question
Share on Google+
3 Replies

P: 94
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.
Feb 23 '13 #2

P: 2
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..
Mar 12 '13 #3

P: 94
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.
Mar 12 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.