I have been strugling wit the "INSERT INTO" statement.
I intend to insert the items that are in a datagridview into An Access Database when a button is clicked. I am using VB.NET 2008 express and Microsoft acces 2007.
At first, I tried to use the listview, but could not get anything done, and so I changed and now I am using a Datagridview.
Below is the code I have so far.
Private Sub btnCpltSale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCpltSale.Click Dim Description As String Dim proValue As Decimal Dim Datesold As Date Dim sql As String myConnToAccess.Open() For Sale As Integer = 0 To DataGridView1.Rows.Count Description = DataGridView1.Rows(Sale).Cells(1).Value proValue = DataGridView1.Rows(Sale).Cells(2).Value Datesold = DataGridView1.Rows(Sale).Cells(3).Value sql = "INSERT INTO tblSales(proDescription, SaleValue, transDate)VALUES (@productname, @productValue, @saleDate)" Dim Comm As New OleDbCommand(sql, myConnToAccess) Comm.Parameters.AddWithValue("@productname", Description) Comm.Parameters.AddWithValue("@productValue", proValue) Comm.Parameters.AddWithValue("@saleDate", Datesold) Comm.ExecuteNonQuery() Comm.Dispose() Next myConnToAccess.Close() End Sub
When the button is clicked, I am getting an error message saying "parameter "@productname" has no default value.However, despite the error, when I check the table, the record is being created successfully. All I do not know is why the error occuring and how to get rid of it.
Any help will greatly be appreciated.