473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

data reader not getting refreshed

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()
  2.  
  3.  
  4.         Using NewSqlConnection As New MySqlConnection(sql_data_connection)
  5.  
  6.              Dim persmast_query As New MySqlCommand(QueryString, NewSqlConnection)
  7.  
  8.             NewSqlConnection.Open()
  9.  
  10.             Using PersmastReader As MySqlDataReader = persmast_query.ExecuteReader()
  11.  
  12.  
  13.  
  14.                 If PersmastReader.HasRows Then
  15.  
  16.  
  17.                While PersmastReader.Read
  18.  
  19.                         UserTLD = PersmastReader.GetString("tldno")
  20.                         UserSign = PersmastReader.GetString("previlage")
  21.                         TldNumber = UserTLD
  22.                         UserValid = True
  23.  
  24.  
  25.                     End While
  26.  
  27.                 Else
  28.  
  29.                   MsgBox("This user is not recogonised !!!", MsgBoxStyle.Critical, "Please Contact Administrator!!")
  30.  
  31.                 End If
  32.                 PersmastReader.Close()
  33.                 PersmastReader.Dispose()
  34.  
  35.  
  36.  
  37.             End Using
  38.  
  39.             NewSqlConnection.Close()
  40.             NewSqlConnection.Dispose()
  41.             persmast_query.Dispose()
  42.  
  43.         End Using
  44. End sub
  45. Thanks in advance
Feb 21 '13 #1
3 1097
Mikkeee
94 64KB
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
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
Mikkeee
94 64KB
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

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

Similar topics

37
by: ajay | last post by:
How to make a web page getting refreshed after a given time interval automatically. HTML Code plz. Tx Ajay
1
by: Mike P | last post by:
I'm using 1 connection to open 3 separate data readers to read data into 3 data grids. However, when I try to use the 2nd reader it says that the first reader must be closed. So I use Close() to...
1
by: mhnazly | last post by:
i'm trying to read data from SQL Server database using data reader and assigned it to a label in my asp.net web application. but when the button is clicked, nothing appears. please help, thanks. ...
4
by: Ram | last post by:
I am using ADO.Net data reader to retrieve data from main frame. I am getting timestamp which is 26 (yyyy-mm-dd hh- mm-ss.123456) bytes as sqltimestamp data type. I am using data reader to...
6
by: Jim Heavey | last post by:
I am new to SqlServer, have been using Oracle in a prior life. I have written a very simple stored procedure in SQL Server and it (the query) looks like the following... Select AD_ID,...
1
by: simonZ | last post by:
I have data reader(I can't create data adapter, because I'm using command.BeginExecuteReader and EndExecuteReader) What is the best way to save data reader to table inside the data set? Any...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, how do you resolve this problem? i have a public procedure in my DataAccessLayer that gets a SqlDataReader how do i close the reader from inside the DataAccessLayer if I'm returning...
2
by: sacha4 | last post by:
I need to make an edit page using data reader. this is my code.. Sub Page_Load() If Not IsPostBack Then Dim conn As SqlConnection Dim cmdSQL As SqlCommand ...
3
by: charvi | last post by:
i hae a ole data reader which contains records extracted from Query.how can i check for end of file in data reader.and i want to know the number of records present in data reader thanks in advance
1
by: zeena | last post by:
I am using a materialized view to get order details from a different schema. I expect my view to get refreshed every BOD. I created my Materialized view with the following code, CREATE MATERIALIZED...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.