1 Replies - 364 Views - Last Post: 22 January 2013 - 04:48 AM Rate Topic: -----

#1 pendaz  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 75
  • Joined: 14-August 12

Strange MySql Exception

Posted 22 January 2013 - 02:48 AM

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:


        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)



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

Is This A Good Question/Topic? 0
  • +

Replies To: Strange MySql Exception

#2 pendaz  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 75
  • Joined: 14-August 12

Re: Strange MySql Exception

Posted 22 January 2013 - 04:48 AM

Double post sry, please delete this thread
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1