1.11M Members

Inserting values of checkbox and radiobutton into SQL databse through vb.net form

 
0
 

how to insert the values of checkbox and radiobuttons in the sql databse using vb.net???

we are getting problem in inserting and don't know what to do................

like i have one form with two text boxes named username and password and one label say gender....which has two checkboxes male and female and another label with two radiobuttons....yes and no....
on the submit button i want to insert the values into database.....made in
SQL server management studio 2008 and em using vb.net 2008

Imports System.Data.SqlClient
Public Class Form1
    Dim con As New SqlConnection
    Dim com As New SqlCommand
    Dim d As New SqlDataAdapter
    Dim da As Integer
    Dim rbtn As String
    Dim a, b As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        con = New SqlConnection("server=abc-pc\sqlexpress;database=abc;trusted_connection=yes")
        con.Open()
        com = New SqlCommand("INSERT INTO user (username,password,bonus,others) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + a + "','" + b + "')", con)
com.ExecuteNonQuery()
        MessageBox.Show("saved",da)
        con.Close()
    End Sub

em getting error at com.executenonquery

 
0
 
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim Gender As String = Nothing
        Dim Decision As String = Nothing
        If chkMale.Checked Then
            Gender = chkMale.Text.ToString
        ElseIf chkFemale.Checked Then
            Gender = chkFemale.Text.ToString
        End If
        If rdYes.Checked Then
            Decision = rdYes.Text.ToString
        Else
            Decision = rdNo.Text.ToString
        End If
    End Sub

Use, like the Above coding and Store the Resultant String Values in the Database.

 
0
 
Imports System.Data.SqlClient
Public Class Form1
    Dim con As New SqlConnection
    Dim com As New SqlCommand
    Dim d As New SqlDataAdapter
    Dim da As Integer
    Dim rbtn As String
    Dim a, b As String
    If chkMale.Checked Then
        a = chkMale.Text.ToString
    ElseIf chkFemale.Checked Then
        a = chkFemale.Text.ToString
    End If
    If rdYes.Checked Then
        b = rdYes.Text.ToString
    Else
        b = rdNo.Text.ToString
    End If
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        con = New SqlConnection("server=abc-pc\sqlexpress;database=abc;trusted_connection=yes")
        con.Open()
        com = New SqlCommand("INSERT INTO user (username,password,bonus,others) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + b + "','" + a + "')", con)
com.ExecuteNonQuery()
        MessageBox.Show("saved",da)
        con.Close()
    End Sub

Use, the Above coding for storing into Database.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article