Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have code in vb.net (visual Studio 2015 + AccessDatabaseEngine.exe)

Dim xSQL As New System.Text.StringBuilder
       xSQL.AppendLine("INSERT INTO tblR")
       xSQL.AppendLine("(dbIc, ")
       xSQL.AppendLine("dbTn, ")
       xSQL.AppendLine("dbQ, ")
       xSQL.AppendLine("dbD, ")
       xSQL.AppendLine("dbU, ")
       xSQL.AppendLine("dbP, ")
       xSQL.AppendLine("dbA, ")
       Using odc As New OleDbConnection(odb)
           odc.Open()
           Dim cmd As New OleDbCommand(xSQL.ToString, odc)
           cmd.Parameters.AddWithValue("@dbIc", txtIc.Text)
           cmd.Parameters.AddWithValue("@dbTn", txtTn.Text)
           cmd.Parameters.AddWithValue("@dbQ", txtqty.Text)
           cmd.Parameters.AddWithValue("@dbD", txtD.Text)
           cmd.Parameters.AddWithValue("@dbU", cbunit.Text)
           cmd.Parameters.AddWithValue("@dbP", txtunitP.Text)
           cmd.Parameters.AddWithValue("@dbA", txtLamt.Text)
           cmd.ExecuteNonQuery()
       End Using


i have accdb

ID autonumber
dbIc Short text
dbTn short text
dvQ Number
dbD long text
dbU short text
dvP Number
dbA Number

at runtime i received

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll


pointing error to
cmd.ExecuteNonQuery()


WHERE I GO WRONG? please help...

What I have tried:

Inserting data to MS Access using VB.net 2015
Posted
Updated 25-Nov-22 22:30pm

1 solution

You did not close the field names set properly, and you forgot to add the VALUES clause to your insert statement. The final statement that you send to access should look like:
SQL
INSERT INTO tblR (dbIc, dbTn, dbQ, dbD, dbU, dbP, dbA) VALUES (?, ?, ?, ?, ?, ?, ?); ")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900