N
Nathan
I'm having a problem updating a database with a datatable. (I'm using
VB.NET 2003 Standard.) I can't figure out the problem, because it's the
same method I've used for tons of other updates that work fine every time.
I create the oledb dataadapter by dragging the table from Server Explorer
onto the form. Then I right-click the adapter and generate the dataset.
This is a sample of the code I use to add a new record to the dataset and
then update:
\\
Dim tblTransactions as DataTable = datDataSet.Transactions
Dim frm as new frmNewTransaction
With frm
.ShowDialog
Dim NewTransaction As DataRow = tblTransactions.NewRow
NewTransaction("Transaction") = .cboTransaction.SelectedItem.ToString
If .txtCheck.Text = "" Then
NewTransaction("CheckNumber") = 0
Else
NewTransaction("CheckNumber") = CInt(.txtCheck.Text)
End If
NewTransaction("EntryDate") = .dtpDate.Value
NewTransaction("Amount") = CDbl(.txtAmount.Text)
NewTransaction("Description") = .txtDescription.Text
NewTransaction("Balanced") = False
tblTransactions.Rows.Add(NewTransaction)
End With
adpTransactions.Update(tblTransactions)
\\
I get the following error when the update method tries to execute: "Syntax
error in INSERT INTO statement"
This is the insert statement generated by the designer:
"INSERT INTO Transactions (Amount, Balanced, CheckNumber, Description,
EntryDate, Transaction) VALUES (?, ?, ?, ?, ?, ?)"
The Transactions table in the dataset has the following columns:
Amount - double
Balanced - boolean
CheckNumber - int
Description - string
EntryDate - dateTime
RegisterID - int (Primary Key)
Transaction - string
Can anyone figure out my problem? Let me know if you need any more
information.
Thanks,
Nathan
VB.NET 2003 Standard.) I can't figure out the problem, because it's the
same method I've used for tons of other updates that work fine every time.
I create the oledb dataadapter by dragging the table from Server Explorer
onto the form. Then I right-click the adapter and generate the dataset.
This is a sample of the code I use to add a new record to the dataset and
then update:
\\
Dim tblTransactions as DataTable = datDataSet.Transactions
Dim frm as new frmNewTransaction
With frm
.ShowDialog
Dim NewTransaction As DataRow = tblTransactions.NewRow
NewTransaction("Transaction") = .cboTransaction.SelectedItem.ToString
If .txtCheck.Text = "" Then
NewTransaction("CheckNumber") = 0
Else
NewTransaction("CheckNumber") = CInt(.txtCheck.Text)
End If
NewTransaction("EntryDate") = .dtpDate.Value
NewTransaction("Amount") = CDbl(.txtAmount.Text)
NewTransaction("Description") = .txtDescription.Text
NewTransaction("Balanced") = False
tblTransactions.Rows.Add(NewTransaction)
End With
adpTransactions.Update(tblTransactions)
\\
I get the following error when the update method tries to execute: "Syntax
error in INSERT INTO statement"
This is the insert statement generated by the designer:
"INSERT INTO Transactions (Amount, Balanced, CheckNumber, Description,
EntryDate, Transaction) VALUES (?, ?, ?, ?, ?, ?)"
The Transactions table in the dataset has the following columns:
Amount - double
Balanced - boolean
CheckNumber - int
Description - string
EntryDate - dateTime
RegisterID - int (Primary Key)
Transaction - string
Can anyone figure out my problem? Let me know if you need any more
information.
Thanks,
Nathan