Lompat ke konten Lompat ke sidebar Lompat ke footer

VB.NET Using RadioButton With MySQL

How To Use A Radio Button With MySQL Database In VbNet

 How To Use A Radio Button With MySQL Database In VbNet VB.NET Using RadioButton With MySQL

In This VB.Net Tutorial  We Will See How To Use A RadioButton Control With MySQL Database
- get value from the selected redio button and insert it into database .
- get value from mysql and select the specific radiobutton 
In Visual Basic.Net  Programming Language And Visual Studio Editor.


 PART 1 

 PART 2 

Project Source Code:

Imports MySql.Data.MySqlClient

Public Class RadioButton_And_MySQL

    Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=test")

    Private Sub ButtonInsert_Click(sender As Object, e As EventArgs) Handles ButtonInsert.Click

        Dim command As New MySqlCommand("INSERT INTO `users`(`username`, `Lang`) VALUES (@usn,@lng)", connection)

        command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = TextBoxUsername.Text

        Dim rdb As String = ""

   ' get selected radio button 
        If RdbCsharp.Checked = True Then

            rdb = "C#"


        ElseIf RdbVbnet.Checked = True Then

            rdb = "VB.NET"

        ElseIf RdbJava.Checked = True Then

            rdb = "Java"

        Else
             ' NONE is the default  
            rdb = "NONE"

        End If

        command.Parameters.Add("@lng", MySqlDbType.VarChar).Value = rdb

        connection.Open()

        If command.ExecuteNonQuery() = 1 Then

            MessageBox.Show("Inserted")

        Else

            MessageBox.Show("Not Inserted")

        End If

        connection.Close()

        RdbCsharp.Checked = False
        RdbJava.Checked = False
        RdbVbnet.Checked = False
        RdbNone.Checked = False

    End Sub

    ' search data and check the radiobutton with the same value as the returned one 
    Private Sub ButtonGET_Click(sender As Object, e As EventArgs) Handles ButtonGET.Click

        Dim adapter As New MySqlDataAdapter("SELECT * FROM `users` WHERE `id` = " & Convert.ToInt16(TextBoxID.Text), connection)
        Dim table As New DataTable()

        adapter.Fill(table)

        TextBoxUsername.Text = table(0)(1)

        If table(0)(2).Equals("C#") Then
            RdbCsharp.Checked = True

        ElseIf table(0)(2).Equals("VB.NET") Then

            RdbVbnet.Checked = True

        ElseIf table(0)(2).Equals("Java") Then

            RdbJava.Checked = True

        Else
            RdbNone.Checked = True

        End If

    End Sub
End Class
      

///////////////OUTPUT:

 How To Use A Radio Button With MySQL Database In VbNet VB.NET Using RadioButton With MySQL




Posting Komentar untuk "VB.NET Using RadioButton With MySQL"