adding to access database
-
right now i'm trying to add data to a database. i think i'm almost their but get this error message "Property access must assign to the property or use its value" this is what code i got Imports System.Data.OleDb Public Class Cust Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim icount As Integer Dim str As String Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PCBank.mdb;") cn.Open() str = "insert into customer values(" & CInt(tbID.Text) & ",'" & tbSur.Text & "','" & tbFor.Text & "')" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery MessageBox.Show(icount) 'displays number of records inserted Catch End Try cn.Close() End Sub End Class can anybody enliten me?
-
right now i'm trying to add data to a database. i think i'm almost their but get this error message "Property access must assign to the property or use its value" this is what code i got Imports System.Data.OleDb Public Class Cust Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim icount As Integer Dim str As String Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PCBank.mdb;") cn.Open() str = "insert into customer values(" & CInt(tbID.Text) & ",'" & tbSur.Text & "','" & tbFor.Text & "')" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery MessageBox.Show(icount) 'displays number of records inserted Catch End Try cn.Close() End Sub End Class can anybody enliten me?
I might have the answer you seek, but I haven't looked in any depth at this problem.
It may be something to do with the insert statement and/or the customer table. Does the table only have 3 columns: an id, a surname and a forename? Is the id column auto-generated (or whatever the term is in MS Access)? Try naming the columns in your insert statement. I don't know what columns your customer table has but it might be something like this:
insert into customer (id, surname, forename) values (99, 'Rogers', 'Dave')
Dave