1

当我按下按钮时,我希望将 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 数据库中不会添加或更改任何信息。

4

1 回答 1

1

我发现如果我查看调试文件夹,更改就会保存在那里。要改变这一点,我必须手动将连接字符串更改为我的 WindowsApplication1 文件夹。

于 2013-06-24T16:05:57.553 回答