Hello , I would like to enquire if how could I put MYSQL Row to a TextBox ?

Here is my code

Private Sub Form1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MySqlConnection = New MySqlConnection
        MySqlConnection.ConnectionString = "server=localhost;Port=3306; user id =root; password=****; database=visualbasic"
        MySqlConnection.Open()

        Dim Myadapter As New MySqlDataAdapter
        Dim Sqlquery = "Select Sec FROM codes where username = '" & Info.Text & "' AND code = '" & Form5.Code.Text & "';"
        Dim command As New MySqlCommand
        command.Connection = MySqlConnection
        command.CommandText = Sqlquery
        Myadapter.SelectCommand = command
        Dim Mydata As MySqlDataReader
        Mydata = command.ExecuteReader
        If Mydata.HasRows = 1 Then
            MsgBox("Blabla") 
        End If
The coloured RED part . How can i change it to send the rows values to a Textbox?
Cause my program will close within a seconds specified . and it uses mysql to check if the value of seconds is how much.
If it is still not very detailed, i am willing to tell more.
(Coloured Green [Sec] Equals to Seconds)
    End Sub

Hi,

check this :

Dim queryString As String = _
      "Select Sec FROM codes where username = '" & Info.Text _
      & "' AND code = '" & Form5.Code.Text & "';"
Using connection As New SqlConnection(connectionString)
    Dim command As New SqlCommand(queryString, connection)
       connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader()
        Try
            If  reader.Read() Then
                TextBox1.Text = Reader(0)
            End If
        Finally
            ' Always call Close when done reading.
            reader.Close()
        End Try
    End Using

You can check this link


Regards
Veena

Hey Veena !
Thank you for your reply ! But i am a newbie to coding .. Hmm, i got a error for this command line.

Using connection As New SqlConnection(connectionString)

May i know what's wrong?

OK i got it working ! Thank you !! I love you ! (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.