无法写入Access数据库

时间:2013-06-20 14:30:48

标签: vb.net-2010

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

1 个答案:

答案 0 :(得分:1)

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