VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 307,168 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,568 people online right now. Registration is fast and FREE... Join Now!




Using combo boxes to insert data in a database

 

Using combo boxes to insert data in a database

sewiwi

20 Aug, 2008 - 02:26 AM
Post #1

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 3



Thanked: 1 times
My Contributions
I want to add data to a database using combo boxes but I keep receiving the syntax in insert into message. Please view my code and tell me where went wrong.
CODE

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Call Validation()
            If bAllPassed = True Then
                Call InsertData()
                MsgBox("Information is saved", MsgBoxStyle.Information, "Save Information")
                Call LockControls()
            Else
                MsgBox("All the fields are compulsory therefore they should be filled", MsgBoxStyle.Information, "Field Validator")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub Validation()
        'Dim msg As String

        'Write sender
        If TextBox1.Text = " " Then
            bAllPassed = False
        Else
            empID = TextBox1.Text
        End If
        If TextBox2.Text = " " Then
            bAllPassed = False
        Else
            empPass = TextBox2.Text
        End If
        If ComboBox1.SelectedItem = "Select Role" Then
            bAllPassed = False
        Else
            empRole = ComboBox1.SelectedItem
        End If

        If TextBox6.Text = " " Then
            bAllPassed = False
        Else
            idNo = TextBox6.Text
        End If
        If TextBox3.Text = " " Then
            bAllPassed = False
        Else
            empName = TextBox3.Text
        End If
        If TextBox4.Text = " " Then
            bAllPassed = False
        Else
            empSurname = TextBox4.Text
        End If
        If ComboBox2.SelectedItem = "Select Job Title" Then
            bAllPassed = False
        Else
            jobTitle = ComboBox2.SelectedItem
        End If
        If ComboBox3.SelectedItem = "Selected Employee Level" Then
            bAllPassed = False
        Else
            empLevel = ComboBox3.SelectedItem
        End If
        If ComboBox4.SelectedItem = "Select Gender" Then
            bAllPassed = False
        Else
            gender = ComboBox4.SelectedItem
        End If
        If TextBox5.Text = " " Then
            bAllPassed = False
        Else
            If IsNumeric(TextBox5.Text) Then
                age = TextBox5.Text
            End If
        End If
        If ComboBox7.SelectedItem = "Select Employment Equit Status" Then
            bAllPassed = False
        Else
            ee = ComboBox7.SelectedItem
        End If
        If ComboBox5.SelectedItem = "Select Marital Status" Then
            bAllPassed = False
        Else
            maritalStatus = ComboBox5.SelectedItem
        End If
        If ComboBox6.SelectedItem = "Select Department Code" Then
            bAllPassed = False
        Else
            deptCode = ComboBox6.SelectedItem
        End If
    End Sub

    Private Sub InsertData()
        Dim comm As New OleDbCommand

        comm.CommandText = "INSERT INTO Employee & #40;Emp_ID,Password,Role,ID_Number,Emp_Name,Emp_Surname,Job_Title,Emp_Role,Gende
r,Age,EE,Marital_Status,Dept_Code)" & _
         "Values & #40;@Emp_ID,@Password,@Role,@ID_Number,@Emp_Name,@Emp_Surname,@Job_Title,@Emp_Ro
le,@Gender,@Age,@EE,@Marital_Status,@Dept_Code)"
        comm.Connection = oleconn
        comm.Parameters.Clear()
        comm.Parameters.Add("Emp_ID", empID)
        comm.Parameters.Add("Password", empPass)
        comm.Parameters.Add("Role", empRole)
        comm.Parameters.Add("ID_Number", idNo)
        comm.Parameters.Add("Emp_Name", empName)
        comm.Parameters.Add("Emp_Surname", empSurname)
        comm.Parameters.Add("Job_Title", jobTitle)
        comm.Parameters.Add("Emp_Role", empLevel)
        comm.Parameters.Add("Gender", gender)
        comm.Parameters.Add("Age", age)
        comm.Parameters.Add("EE", ee)
        comm.Parameters.Add("Marital_Status", maritalStatus)
        comm.Parameters.Add("Dept_Code", deptCode)


        If oleconn.State = ConnectionState.Closed Then
            oleconn.Open()
        End If

        comm.ExecuteNonQuery()
    End Sub


User is offlineProfile CardPM
+Quote Post



Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:38PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month