我在Visual Studio 2010中创建了一个表单&以下是我正在使用的代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
Dim dbSource = "Data Source=|DataDirectory|\Membership.accdb"
Dim con As New OleDb.OleDbConnection
con.ConnectionString = dbProvider & dbSource
con.Open()
Dim sql = "INSERT INTO Memberdetail (Membername, Memberadd, Membercontact, Memberphone1, Memberphone2, Membersince) VALUES (?, ?, ?, ?, ?, ?)"
Using cmd = New OleDb.OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("@p1", Me.Memname.Text)
cmd.Parameters.AddWithValue("@p2", Me.Memadd.Text)
cmd.Parameters.AddWithValue("@p3", Me.Memcontact.Text)
cmd.Parameters.AddWithValue("@p4", Me.Memphone1.Text)
cmd.Parameters.AddWithValue("@p5", Me.Memphone2.Text)
cmd.Parameters.AddWithValue("@p6", Me.DateTimePicker1.Text)
cmd.ExecuteNonQuery()
End Using
Me.Close()
End Sub
但是,这会每次编辑表格中唯一可用的数据,并且在输入新数据时不会向表格添加新行。
我错了。
请帮忙。