Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Saving combo box and radio button items to SQL server05 Database

$
0
0
good day everyone,

im trying to make a registration form and trying to save what's being input to the database, but im really having a hard time saving them and i have some errors when i put the codes i made,

here is the form i made:

Name:  registration.JPG
Views: 145
Size:  48.6 KB

and here is the code with out the radio button and combobox:

Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Public Class Registration

Dim conn As New SqlConnection("Data Source=RAY2X\SQLEXPRESS;Initial Catalog=ray2x;Integrated Security=True")
Dim command As New SqlCommand
Dim dataread As SqlDataReader



Private Sub Registration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

command.Connection = conn

End Sub

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

If (txtfirst.Text <> "" Or txtlast.Text <> "" Or txtadd.Text <> "" Or txtemail.Text <> "" Or txtuser.Text <> "" Or txtpass.Text <> "") Then

Try

conn.Open()
command.CommandText = "Insert into Login ( username , password ) values ('" & txtuser.Text & "' , '" & txtpass.Text & "' )"
command.CommandText = "Insert into Personal_Information ( First_Name, Last_Name, Address, Contact_No, Email_Address, SSS_No, TIN_No, Bank_Account ) values ('" & txtfirst.Text & "' , '" & txtlast.Text & "' , '" & txtadd.Text & "' , '" & txtcontact.Text & "' , '" & txtemail.Text & "' , '" & txtsss.Text & "' , '" & txttin.Text & "' , '" & txtbank.Text & "')"
command.ExecuteNonQuery()
conn.Close()

Catch ex As Exception

MsgBox(ex.Message)

End Try


End If
Timer1.Start()
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click, Button3.Click

txtfirst.Clear()
txtfirst.Enabled = True
txtlast.Clear()
txtlast.Enabled = True
txtadd.Clear()
txtadd.Enabled = True
txtemail.Clear()
txtemail.Enabled = True
txtuser.Clear()
txtuser.Enabled = True
txtpass.Clear()
txtpass.Enabled = True

btncancel.Enabled = True
btnsave.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

loading.Increment(1)

If loading.Value = 100 Then
Timer1.Stop()

MsgBox("Regstration Successful! ! !")

Login.Show()
Me.Hide()

End If

End Sub

End Class

now here is the code i made for the radio button and combobox which give me the error ( "object reference not set to an instance of an object") :

'Dim Day As Integer = Integer.Parse(ComboBoxday.SelectedItem.ToString())
'Dim Month As Integer = Integer.Parse(ComboBoxmonth.SelectedItem.ToString())
'Dim Year As Integer = Integer.Parse(ComboBoxyear.SelectedItem.ToString())
'Dim MyDate As New DateTime(Year, Month, Day)
'Dim Male As Char
'Dim Female As Char

'command.CommandText = "Insert into Personal_Information ( Month, Day, Year ) values ('" & Month & "' , '" & Day & "' , '" & Year & "')"
'If (rbmale.Checked = True) Then
'command.CommandText = "Insert into Personal_Information ( Gender ) values ( '" & Male & "' )"
'Else
'command.CommandText = "Insert into Personal_Information ( Gender ) values ( '" & Female & "' )"
'End If


can someone help me how to code them properly? i dont know how to do things ATM because im still reading about the things needed for the VS 10 and im still noob with it. :)

pretty please everyone. :)

thank you in advance
Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>