1

I'm having trouble trying to read from a MySQL databse using VB.NET, the error message I get is "ArgumentExcpetion was unhandled"

Also, the reading should return 'F', since this is the value allocated on that specific place on the table.

Imports MySql.Data.MySqlClient
Public Class Form1
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim query As String = "SELECT DO FROM klein WHERE COMMAND='DELETE'"
        Dim connStr As String = "server=" & TextBox1.Text & ";" _
            & "user id=" & TextBox2.Text & ";" _
            & "password=" & TextBox3.Text & ";" _
            & "database=hidro201_liberato"
        Dim connection As New MySqlConnection(connStr)
        Dim cmd As New MySqlCommand(query, connection)
        connection.Open()
        Dim reader As MySqlDataReader
        reader = cmd.ExecuteReader()
        While reader.Read()
            TextBox4.Text = (reader.GetChar(1))   '<- **problem is here**
        End While
    End Sub
End Class

3 Answers 3

1

The field index is zero based.

TextBox4.Text = (reader.GetChar(0))

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getchar.aspx

Parameter i: "The zero-based column ordinal."

Sign up to request clarification or add additional context in comments.

Comments

0

You have only one column in your query and the index of the column should be zero

TextBox4.Text = (reader.GetChar(0))   

This is for SqlServer but the rules are the same for a MySqlDataReader

2 Comments

I'm having another problem, I want to read an entry on the database and update is as follows, although it's not updating and it's also not giving any kind of error
sorry but I can't help without seeing the code that tries the update
0

TextBox4.Text = (reader.GetChar("Name of column to get the value")) All the best

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.