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 데이터베이스에 추가되거나 변경되지 않습니다.
그래서 문제가 무엇입니까? –
팁 :이 코드는 프로그램을 중단시킵니다. 루프는 i가 1보다 크면 계속 진행되며 반복 할 때마다 1을 더합니다. 또한 모든 반복에서 연결을 열고 닫는 것은 좋지 않습니다. 작업을 완료 한 후 한 번 열어 닫습니다. – Abbas
@Bill Gregg 문제없이 실행되지만 액세스 데이터베이스에는 저장되지 않습니다. 여전히 동일한 후에 데이터베이스를 열 때. –