I'm attempting to read values from a database into my application, i have a table with a number of entries all of Type: Text
heres what im using to read the values:
Now for some reason i can't seem to understand, some of the entries in the table read perfectly, yet others throw the following error:
It seems strange to me that i'm getting this error on only some of the records in the table - i've reviewed the data in table and can't seem to find any kind of pattern.
any suggestions?
Thanks in advance
heres what im using to read the values:
frmMain.Cursor = Cursors.WaitCursor
Dim conn As New MySqlConnection
conn.ConnectionString = "*************"
'Get user data
Try
conn.Open()
'Dim stm As String = "SELECT Nickname, Enabled, License, Version, Password, email, news, logincount, lastloggedin FROM Users WHERE Username='" & SELusername & "'"
Dim stm As String = "SELECT * FROM Users WHERE Username='" & SELusername & "'"
Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
Dim reader As MySqlDataReader = cmd.ExecuteReader()
With frmMain
username = SELusername
frmMain.txtUsername.Text = username
reader.Read()
nickname = reader.GetString("nickname")
oldnickname = reader.GetString("nickname")
.txtNickname.Text = nickname
Enabled = reader.GetString("enabled")
oldEnabled = reader.GetString("enabled")
frmMain.cmbEnabled.Text = Enabled
If Enabled = "1" Then
.cmbEnabled.Text = "Yes"
ElseIf Enabled = "0" Then
.cmbEnabled.Text = "No"
End If
License = reader.GetString("license")
oldLicense = reader.GetString("license")
.txtLicense.Text = License
Version = reader.GetString("version")
oldVersion = reader.GetString("version")
.txtVersion.Text = Version
Password = reader.GetString("password")
oldPassword = reader.GetString("password")
frmMain.txtPassword.Text = Password
logincount = reader.GetString("LoginCount")
.txtLoginCount.Text = logincount
lastloggedin = reader.GetString("lastloggedin")
.txtLastLoggedIn.Text = lastloggedin
news = reader.GetString("news")
oldNews = reader.GetString("news")
If news = "1" Then
.cmbNews.Text = "Yes"
ElseIf news = "0" Then
.cmbNews.Text = "No"
End If
email = reader.GetString("email")
oldEmail = reader.GetString("email")
.txtEmail.Text = email
reader.Close()
frmMain.Cursor = Cursors.Default
End With
Catch ex As MySqlException
MsgBox("Error: " & ex.ToString())
Finally
conn.Close()
End Try
Now for some reason i can't seem to understand, some of the entries in the table read perfectly, yet others throw the following error:
Quote
Error: MySql.Data.MySqlClient.MySqlException (0x80004005): Invalid attempt to access a field before calling read()
at MySql.Data.MySqlClient.ResultSet.get_item(int32 index)
at MySql.Data.MySqlClient.MySqlDataReader.GetFieldValue(int32 index, Boolean checkNull)
at MySql.Data.MySqlClient.MySqlDataReader.Getstring(int32 i)
at MySql.Data.MySqlClient.MySqlDataReader.Getstring(String Column)
at MySql.Data.MySqlClient.ResultSet.get_item(int32 index)
at MySql.Data.MySqlClient.MySqlDataReader.GetFieldValue(int32 index, Boolean checkNull)
at MySql.Data.MySqlClient.MySqlDataReader.Getstring(int32 i)
at MySql.Data.MySqlClient.MySqlDataReader.Getstring(String Column)
It seems strange to me that i'm getting this error on only some of the records in the table - i've reviewed the data in table and can't seem to find any kind of pattern.
any suggestions?
Thanks in advance