Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

Cannot Insert data into MS Access

$
0
0
I have created a new project using Visual Studio 2010 under windows application - Window Forms. When the the user fills out the two textboxes and clicks on add customer, the details should be saved onto to the access 2007 database but for some reason, this doesnt seem to be working.

There's a simple Access 2007 database with one table.

There are two text boxes in the form with a add button. The add button has the following code:

Dim sql As String = "INSERT INTO CustomerInformation (FirstName,LastName) VALUES (@f1,@f2)"
Dim conn As OleDbConnection = New OleDbConnection(connectionString:="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\CustomerDetails.accdb")
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
conn.Open()


cmd.Parameters.AddWithValue("@f1", txtFirstName.Text)
cmd.Parameters.AddWithValue("@f2", txtLastName.Text)

cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()

I have added the imports system.data.oledb above public class Form1.

Please attachment for the project solution files and coding.
Attached Files

Viewing all articles
Browse latest Browse all 42215

Trending Articles



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