How to send data to an access table through a comboBox and maskedtextBox selection?

helio_matcha

New member
Joined
Sep 28, 2007
Messages
4
Programming Experience
Beginner
Hi, guys i'm currently working with VB and access.

Few days i used a form to send data to an access table, it was pretty easy and working fine but now i'm trying out something different.

On my form i have two comboBoxs and one maskedTextBox.

1.comboBox1 it's gender{male,female}
2.comboBox2 is position {manager,administration,salesperson}

and i'm using the maskedTextBox for contact number

I wrote the code and it's not working, i think i didn't set properly the comboBoxs and the maskedTextBox, can somebody help me?

This is the error message i got:
System.Data.OleDb.OleDbException: Data type mismatch in criteria expression

And here is my code:

VB.NET:
'provides classes that are required to connect to OLE DB data sources
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    'The System.Data.OleDb.OleDbConnection class represents a connection to OleDb data source
    Dim cn As OleDbConnection
    'The System.Data.OleDb.OleDbCommand class represents a SQL statement or stored procedure 
    'that is executed in a database by an OLE DB provider. 
    Dim cmd As OleDbCommand
    Dim icount As Integer
    Dim str, gender, position, contact As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        gender = cmbGender.SelectedText 'comboBox 1 
        position = cmbPosition.SelectedText 'comboBox 2
        contact = msktxtContact.Text 'maskedTextBox

        Try
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\2007_Final Sem\BSD\projectRegistration.mdb;")
            cn.Open()
            str = "insert into testing ([gender],[position],[contactNo]) values ('" & gender & "', '" & position & "', '" & contact & "')"

            cmd = New OleDbCommand(str, cn)
            icount = cmd.ExecuteNonQuery()
            MessageBox.Show("Congratulations")

        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
        cn.Close()
    End Sub
End Class
 
Back
Top