当我按下按钮时,我希望将 Sname 和 SNo 写入数据库。这是我的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\cerns1\Local Settings\Application Data\Temporary Projects\WindowsApplication1\testdb.accdb"
Dim cnn As New OleDbConnection(ConnString)
' Create a new row.
Dim newStudentRow As testdbDataSet.StudentRow
newStudentRow = Me.TestdbDataSet.Student.NewStudentRow()
' Save the new row to the database
Dim i As Integer = 2
Dim SNo As Integer = 1
Do While i > 1
cnn.Open()
'StudentTableAdapter.Insert("WOW", SNo)
Me.TestdbDataSet.Student.Rows.Add(newStudentRow)
Me.StudentTableAdapter.Update(Me.TestdbDataSet.Student)
SNo = SNo + 1
i = i + 1
cnn.Close()
Loop
End Sub
执行后,Access 数据库中不会添加或更改任何信息。