HighTechTalks DotNet Forums  

OdbcDataReader.Read() changing value after use.

Dotnet Framework (ODBC.net) microsoft.public.dotnet.framework.odbcnet


Discuss OdbcDataReader.Read() changing value after use. in the Dotnet Framework (ODBC.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jason Kelley
 
Posts: n/a

Default OdbcDataReader.Read() changing value after use. - 12-06-2004 , 04:05 PM






I don't know if this is a bug or poor coding on my part, but when I use the
..Read() function, the value of it changes and it jumps past my If box. When
I ran a debug on the code after the execution of .ExecuteReader() there is a
value in MyReader("lastchange"), but when it runs the test statement,
MyReader advances and the test fails. Suggestions?

'This is the code that I am using.
Dim MyConString As String
Dim MySQLString As String
MyConString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=s01;
DATABASE=time-trax; UID=common; OPTION=3"
MySQLString = "SELECT MAX(action_time) as lastchange FROM data WHERE
employee_name = " & intAgentID

Dim MyConnection As New OdbcConnection(MyConString)
Dim MyCommand As New OdbcCommand(MySQLString, MyConnection)
MyConnection.Open()

Dim MyReader As OdbcDataReader
MyReader = MyCommand.ExecuteReader()

If MyReader.Read() Then
GetLastActionDateTime = MyReader("lastchange")
End If

MyReader.Close()
MyConnection.Close()

Extra Info:
Environment - Visual Basic.NET
SQL Server - MySQL
Data Connection - ODBC.NET



Reply With Quote
  #2  
Old   
Jason Kelley
 
Posts: n/a

Default Re: OdbcDataReader.Read() changing value after use. - 12-06-2004 , 06:59 PM






Okay, found it, now i feel foolish. I had added a watch for .Read() to
ensure that it was triggering a statement and had left it in the watch
group. When i had moved on to tackle this problem, i did not clean out my
watch group so it was executing .Read() twice. Since it moved the data
pointer, this would make sense that the value would change when it should
not be.

"Jason Kelley" <jckelley (AT) yahoo (DOT) com> wrote

Quote:
I don't know if this is a bug or poor coding on my part, but when I use the
.Read() function, the value of it changes and it jumps past my If box. When
I ran a debug on the code after the execution of .ExecuteReader() there is
a value in MyReader("lastchange"), but when it runs the test statement,
MyReader advances and the test fails. Suggestions?

'This is the code that I am using.
Dim MyConString As String
Dim MySQLString As String
MyConString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=s01;
DATABASE=time-trax; UID=common; OPTION=3"
MySQLString = "SELECT MAX(action_time) as lastchange FROM data WHERE
employee_name = " & intAgentID

Dim MyConnection As New OdbcConnection(MyConString)
Dim MyCommand As New OdbcCommand(MySQLString, MyConnection)
MyConnection.Open()

Dim MyReader As OdbcDataReader
MyReader = MyCommand.ExecuteReader()

If MyReader.Read() Then
GetLastActionDateTime = MyReader("lastchange")
End If

MyReader.Close()
MyConnection.Close()

Extra Info:
Environment - Visual Basic.NET
SQL Server - MySQL
Data Connection - ODBC.NET





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.