|
| Using odbcDataReader |
 |
Tue, 1 Apr 2008 16:47:34 +0000 |
I'm attempting to read a value from a database using the odbcDataReader. My
query doesn't seem to be returning any records... I've confirmed that the
connection is actually opening and MyReader.RecordsAffected.ToString returns '1'
(as expected). Here is my code...
Imports System.Data.Odbc
Partial Class University_PostTraining_PostItem
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim MyConnection As OdbcConnection
Dim MyConnectString As String
Dim MyCommand As New OdbcCommand
Dim MyQueryString As String
Dim MyReader As OdbcDataReader
'*********************************************************************
'*** Open Connection to Database
'*********************************************************************
MyConnectString = "Dsn=MySQL Database on
Localhost;uid=mysql;pwd=mysql"
MyConnection = New OdbcConnection(MyConnectString)
MyConnection.Open()
MyCommand.Connection = MyConnection
MyQueryString = "select FirstName, LastName, MiddleInt from MyTable
where id = 1"
MyCommand.CommandText = MyQueryString
MyReader = MyCommand.ExecuteReader()
If MyReader.Read() Then
lblFirstName.Text = MyReader.Item("FirstName")
Else
lblFirstName.Text = "Error"
End If
End Sub
End Class
|
| Post Reply
|
| Re: Using odbcDataReader |
 |
Tue, 1 Apr 2008 18:33:32 +0000 |
So are you saying MyReader.Read() returns false?
|
| Post Reply
|
|
|
|
|
|
|
|
|
|