Jump to content

[SOLVED] Visual Basic / MySQL


jakebur01

Recommended Posts

Hello,

 

I just got started with Visual Basic a few weeks ago. I have a text field named txtZipbox and a button named btnZip. I am wanting to retrieve the data WHERE my Zip column = what someone typed in the txtZipbox. I get an error back saying that txtZipbox.Text is not a column. I know that it's not a column. What do I need to add onto this to make it happen?

 

`Jake

 

Private Sub btnZip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZip.Click
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim myData As New DataTable
        Dim SQL As String

        SQL = "SELECT * FROM smithssc WHERE Zip = txtZipbox.Text"


        conn.ConnectionString = myConnString
        Try
            conn.Open()

            Try
                myCommand.Connection = conn
                myCommand.CommandText = SQL

                myAdapter.SelectCommand = myCommand
                myAdapter.Fill(myData)

                dgvStatus.DataSource = myData
                dgvStatus.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
            Catch myerror As MySqlException
                MsgBox("There was an error reading from the database: " & myerror.Message)
            End Try
        Catch myerror As MySqlException
            MessageBox.Show("Error connecting to the database: " & myerror.Message)
        Finally
            If conn.State <> ConnectionState.Closed Then conn.Close()
        End Try
    End Sub

Link to comment
https://forums.phpfreaks.com/topic/47838-solved-visual-basic-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.