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时。 –
我一直在改变我的方法,你的方法.. –
我很高兴它帮助。 –