This is a multi-part message in MIME format.
------=_NextPart_000_0008_01C355D7.007D5810
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I'm trying to insert a record into an Access database, but am getting =
the error "System.Data.OleDb.OleDbException: Syntax error in INSERT INTO =
statement." I've checked and rechecked the code. I've tried variations, =
like adding .toString after name.text, nothing I'm doing is working. I =
hope someone can see what I'm missing.=20
Thanks for your help!=20
Lynnette=20
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As =
System.EventArgs) Handles btnAdd.Click
Dim strSQL As String
Dim cnn As New OleDbConnection(Constants.OleDbConnectionString)
strSQL =3D "SELECT * FROM Radios"
Dim objCommand As OleDbCommand =3D New OleDbCommand(strSQL, cnn) =
Dim objDataAdapter As New OleDbDataAdapter()
objDataAdapter.SelectCommand =3D objCommand
Dim objDataSet As New DataSet()
objDataAdapter.Fill(objDataSet, "Radios")
Dim objTable As DataTable
objTable =3D objDataSet.Tables("Radios")
Dim chkM As CheckBox =3D Me.chkMike
Dim updval As String
If chkM.Checked Then
updval =3D "1"
Else
updval =3D "0"
End If
Dim chkC As CheckBox =3D Me.chkCharger
Dim updval2 As String
If chkC.Checked Then
updval2 =3D "1"
Else
updval2 =3D "0"
End If
Dim objDataRow As DataRow
objDataRow =3D objTable.NewRow()
objDataRow("intRIN6Digit") =3D CInt(txtRIN.Text) 'integer =
datatype; Primary key
objDataRow("strAssignment") =3D txtAssignment.Text
objDataRow("strCall") =3D txtCall.Text
objDataRow("strDivision") =3D ddlDiv.SelectedItem.Text
objDataRow("strDistrict-Section") =3D txtSecLoc.Text
objDataRow("strTalkGroup") =3D txtTG.Text
objDataRow("strSerialNumber") =3D txtSerial.Text
objDataRow("strModel") =3D txtModel.Text
objDataRow("bPSMike") =3D CBool(updval)
objDataRow("bIndividualCharger") =3D CBool(updval2)
If Len(Me.txtChargerNo.Text) > 1 Then 'integer =
datatype
objDataRow("intChargerNumber") =3D CInt(txtChargerNo.Text)
Else
objDataRow("intChargerNumber") =3D =
Convert.IsDBNull(txtChargerNo.Text)
End If
objDataRow("strOwner") =3D txtOwner.Text
If Len(Me.txtScan.Text) > 1 Then 'integer =
datatype
objDataRow("intAssetTagNo") =3D CInt(txtScan.Text)
Else
objDataRow("intAssetTagNo") =3D =
Convert.IsDBNull(txtScan.Text)
End If
objDataRow("dtSentForRepair") =3D txtRepair.Text
objDataRow("Count") =3D txtCount.Text
objDataRow("strRemarks") =3D txtRemarks.Text
objTable.Rows.Add(objDataRow)
Dim objCommandBuilder As New OleDbCommandBuilder(objDataAdapter)
objDataAdapter.InsertCommand =3D =
objCommandBuilder.GetInsertCommand()
objDataAdapter.Update(objDataSet, "Radios")
lblConfirm.Text =3D ("The Record has been added.")
txtRIN.Text =3D Nothing
txtAssignment.Text =3D Nothing
txtCall.Text =3D Nothing
txtSecLoc =3D Nothing
txtTG.Text =3D Nothing
txtSerial.Text =3D Nothing
txtModel.Text =3D Nothing
txtChargerNo.Text =3D Nothing
txtOwner.Text =3D Nothing
txtScan.Text =3D Nothing
txtRepair.Text =3D Nothing
txtCount.Text =3D Nothing
txtRemarks.Text =3D Nothing
updval =3D Nothing
updval2 =3D Nothing
strSQL =3D Nothing
objCommandBuilder.Dispose()
objDataSet.Dispose()
objDataAdapter.Dispose()
cnn.Close()
End Sub
------=_NextPart_000_0008_01C355D7.007D5810
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><SPAN class=3DnormalTextSmall><FONT face=3DArial size=3D2>I'm =
trying to insert a=20
record into an Access database, but am getting the error=20
"System.Data.OleDb.OleDbException: Syntax error in INSERT INTO =
statement." I've=20
checked and rechecked the code. I've tried variations, like adding =
.toString=20
after name.text, nothing I'm doing is working. I hope someone can see =
what I'm=20
missing. <BR><BR>Thanks for your help! <BR>Lynnette =
<BR><BR></FONT><PRE><BR>
<BR>
<FONT face=3DArial size=3D2> Private Sub btnAdd_Click(ByVal sender As =
System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
<BR>
Dim strSQL As String
Dim cnn As New OleDbConnection(Constants.OleDbConnectionString)
<BR>
<BR>
strSQL =3D "SELECT * FROM Radios"
<BR>
Dim objCommand As OleDbCommand =3D New OleDbCommand(strSQL, =
cnn)<BR> Dim objDataAdapter As New OleDbDataAdapter()
objDataAdapter.SelectCommand =3D objCommand
<BR>
<BR>
Dim objDataSet As New DataSet()
objDataAdapter.Fill(objDataSet, "Radios")
<BR>
Dim objTable As DataTable
objTable =3D objDataSet.Tables("Radios")
<BR>
Dim chkM As CheckBox =3D Me.chkMike
Dim updval As String
If chkM.Checked Then
updval =3D "1"
Else
updval =3D "0"
End If
<BR>
Dim chkC As CheckBox =3D Me.chkCharger
Dim updval2 As String
If chkC.Checked Then
updval2 =3D "1"
Else
updval2 =3D "0"
End If
Dim objDataRow As DataRow
objDataRow =3D objTable.NewRow()
objDataRow("intRIN6Digit") =3D CInt(txtRIN.Text) 'integer =
datatype; Primary key
objDataRow("strAssignment") =3D txtAssignment.Text
objDataRow("strCall") =3D txtCall.Text
objDataRow("strDivision") =3D ddlDiv.SelectedItem.Text
objDataRow("strDistrict-Section") =3D txtSecLoc.Text
objDataRow("strTalkGroup") =3D txtTG.Text
objDataRow("strSerialNumber") =3D txtSerial.Text
objDataRow("strModel") =3D txtModel.Text
objDataRow("bPSMike") =3D CBool(updval)
objDataRow("bIndividualCharger") =3D CBool(updval2)
If Len(Me.txtChargerNo.Text) > 1 Then =
'integer datatype
objDataRow("intChargerNumber") =3D CInt(txtChargerNo.Text)
Else
objDataRow("intChargerNumber") =3D =
Convert.IsDBNull(txtChargerNo.Text)
End If
objDataRow("strOwner") =3D txtOwner.Text
If Len(Me.txtScan.Text) > 1 Then 'integer =
datatype
objDataRow("intAssetTagNo") =3D CInt(txtScan.Text)
Else
objDataRow("intAssetTagNo") =3D =
Convert.IsDBNull(txtScan.Text)
End If
objDataRow("dtSentForRepair") =3D txtRepair.Text
objDataRow("Count") =3D txtCount.Text
<BR>
objDataRow("strRemarks") =3D txtRemarks.Text
<BR>
objTable.Rows.Add(objDataRow)
<BR>
Dim objCommandBuilder As New OleDbCommandBuilder(objDataAdapter)
objDataAdapter.InsertCommand =3D =
objCommandBuilder.GetInsertCommand()
objDataAdapter.Update(objDataSet, "Radios")
<BR>
lblConfirm.Text =3D ("The Record has been added.")
<BR>
txtRIN.Text =3D Nothing
txtAssignment.Text =3D Nothing
txtCall.Text =3D Nothing
txtSecLoc =3D Nothing
txtTG.Text =3D Nothing
txtSerial.Text =3D Nothing
txtModel.Text =3D Nothing
txtChargerNo.Text =3D Nothing
txtOwner.Text =3D Nothing
txtScan.Text =3D Nothing
txtRepair.Text =3D Nothing
txtCount.Text =3D Nothing
txtRemarks.Text =3D Nothing
updval =3D Nothing
updval2 =3D Nothing
strSQL =3D Nothing
objCommandBuilder.Dispose()
objDataSet.Dispose()
objDataAdapter.Dispose()
cnn.Close()
End Sub
</FONT></PRE></SPAN></DIV></BODY></HTML>
------=_NextPart_000_0008_01C355D7.007D5810--