Add data problem

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
I need to add the data by three text boxes and coding is shown as below, there is no error popped up for this but the data cannot be added. May i know why? Thank you.

VB.NET:
        Dim DBPath As String
        DBPath = System.AppDomain.CurrentDomain.BaseDirectory & "edatabase.mdb"
        OleDbConnection1 = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "DATA SOURCE=" & DBPath)
 
        Dim Command As OleDb.OleDbCommand
        Dim SQLSTRING As String = "SELECT * FROM Employee"
        Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLSTRING, OleDbConnection1)

            Command = New OleDb.OleDbCommand("INSERT INTO Employee (ID, Name, ContactNo) " & "VALUES (EId.text, EName.text, EContactNo.text)", OleDbConnection1)
            Command.Parameters.Add("EID.text", OleDb.OleDbType.Char, 200, "ID")
            Command.Parameters.Add("EName.text", OleDb.OleDbType.VarChar, 200, "Name")
            Command.Parameters.Add("EContactNo.text", OleDb.OleDbType.VarChar, 200, "ContactNo")
            DAdapter.InsertCommand = Command
 
i am little confused on your insert statement, i did understand why you using "&" before values and while passing parameters you should use
values(?,?,?,?)... instead of directly assigning the textbox values
 
Back
Top