VB.net에서 Microsoft Access 데이터베이스에 삽입하려고합니다. 데이터베이스 (그리드보기에서 볼 수 있음)에서 읽을 수는 있지만 데이터베이스에 삽입 할 수는 없습니다. 문제가있는 곳을 모르겠습니다.데이터베이스에 Microsoft Access 2003을 삽입하는 중 VB.net을 사용하지 못했습니다.
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Public ctr As Integer
Dim bm As BindingManagerBase
Dim dr As DataRow, dt As DataTable
Dim flag As Integer, tid As Integer, tname As String
Dim totalrow As Integer, currentrow As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ShowroomDataSet.customer' table. You can move, or remove it, as needed.
bm = Me.BindingContext(ShowroomDataSet, "customer")
bm.Position = 0
Me.CustomerTableAdapter.Fill(Me.ShowroomDataSet.customer)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
Dim y As String
bm.Position = bm.Count - 1
x = ShowroomDataSet.customer(bm.Position).cid
y = ShowroomDataSet.customer(bm.Position).cname
TextBox1.Text = x
TextBox2.Text = y
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'save
'enable all buttons except save
If flag = 1 Then
dt = ShowroomDataSet.Tables("customer")
dr = dt.NewRow()
dr!cid = Val(TextBox1.Text)
dr!cname = TextBox2.Text
dt.Rows.Add(dr)
End If
If flag = 2 Then
dr.Delete()
End If
If flag = 3 Then
dt = ShowroomDataSet.Tables("customer")
dr = dt.Rows.Find(tid)
dr.BeginEdit()
dr!cid = Val(TextBox1.Text)
dr!name = TextBox2.Text
dr.EndEdit()
End If
'Me.CustomerTableAdapter.Update(Me.ShowroomDataSet.customer)
'Me.CustomerTableAdapter.Fill(Me.ShowroomDataSet.customer)
flag = 0
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'add
'disable all buttons except save
Dim len As Integer
TextBox1.Text = " "
TextBox2.Text = " "
flag = 1
TextBox1.Focus()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
dt = ShowroomDataSet.Tables("customer")
len = dt.Rows.Count - 1
dr = dt.Rows(len)
End Sub
End Class
오류나 고장을 : 이 내가 일을하지 오전 것입니다. 도와주세요.
오류 메시지? 당신은 대개 VS가 프로젝트 폴더에서 바인드 폴더로 액세스 파일을 복사한다는 것을 알고 있습니다. 즉, 각각의 실행마다 새로운 복사본을 작성한다는 의미입니까? 동작은 파일의 속성 창에서 변경할 수 있습니다 -> 출력 디렉토리에 복사 : NEVER – igrimpe
@ 오류가 없습니다. 추가 된 행은 Access에 반영되어야합니다. 그렇지 않습니다. 어떻게해야합니까? –
올바른 파일을 확인하셨습니까? 앞에서 설명한대로 : 기본적으로 (일반적으로 비어있는) Access db 파일은 프로젝트 디렉토리에서 실행 파일이있는 하위 디렉토리 (예 :/bin/debug)로 복사됩니다. 그래서 매번 실행하면 변경된 내용이 모두 덮어 쓰여 지므로 마지막 실행의 모든 변경 사항이 손실됩니다. – igrimpe