0
這是插入到數據庫的代碼微軟訪問, 但出現錯誤。說插入錯誤 請告訴我爲什麼它會是這樣的。並給我想法如何解決這個問題。插入數據訪問數據庫失敗
感謝從文本
首先收集數據,然後 ,然後將代碼選擇數據表 ,然後把數據集中 是插入到數據庫之後。 我沒有看到這個問題
If txtCode.Text = "" Then
txtCode.Focus()
ElseIf cmbCneeName.Text = "" Then
cmbCneeName.Focus()
ElseIf txtCneeAddress1.Text = "" Then
txtCneeAddress1.Focus()
ElseIf txtCneeAddress2.Text = "" Then
txtCneeAddress2.Focus()
Else
Dim acces_da As OleDbDataAdapter
Dim cm As OleDbCommand
Dim acces_ds As DataSet
Dim datarowtblshipper As DataRow
Dim cmdbuilder As OleDbCommandBuilder
cm = New OleDbCommand
With cm
.Connection = DBconnection()
.CommandText = "select * from TblConsignee where con_code='" & txtCode.Text & "'"
End With
acces_da = New OleDbDataAdapter
acces_ds = New DataSet
acces_da.SelectCommand = cm
cmdbuilder = New OleDbCommandBuilder(acces_da)
acces_da.Fill(acces_ds)
Try
datarowtblshipper = acces_ds.Tables(0).NewRow
datarowtblshipper("Con_Code") = txtCode.Text
datarowtblshipper("Con_Comp") = cmbCneeName.Text
datarowtblshipper("Con_Add1") = txtCneeAddress1.Text
datarowtblshipper("Con_Add2") = txtCneeAddress2.Text
datarowtblshipper("Con_Add3") = txtCneeAddress3.Text
datarowtblshipper("Con_Add4") = txtCneeAddress4.Text
datarowtblshipper("Con_PCode") = txtCneePostCode.Text
datarowtblshipper("Con_tel") = txtCneePhoneNo.Text
datarowtblshipper("Contents") = txtCneeContents.Text
datarowtblshipper("destination") = txtDestination.Text
datarowtblshipper("Con_Cont") = txtAttention.Text
datarowtblshipper("zone") = tzone.Text
acces_ds.Tables(0).Rows.Add(datarowtblshipper)
cmdbuilder.GetInsertCommand()
acces_da.Update(acces_ds)
MsgBox("New Data Inserted!")
Catch
MsgBox("Error occured : " & vbCrLf & Err.Description, vbExclamation, "error")
End Try
End If
我喜歡你的代碼..,可以使用..,實際上我嘗試填充所有數據到數據集,然後使用數據集來更新數據庫.. 使用functiong GetInsertCommand(),他們有GetUpdateCommand,甚至GetDeleteCommand時。 –
我一直在改變我的方法,你的方法.. –
我很高興它幫助。 –