cwnonthehill
Member
- Joined
- Nov 5, 2012
- Messages
- 20
- Programming Experience
- 1-3
Hey guys, I'm having a little trouble making multiple row inserts to different tables. Below is my code. The idea is basically to create new rows in the dataset, then Insert those new rows to my SQL database. The first set (tblComplaint) gets inserted fine. Then when it attempts to Insert tblReporter, it says ...
"Missing the DataColumn 'Date' in the DataTable 'tblReporter' for the SourceColumn 'Date'."
So I'm assuming the problem is that it's still trying to insert the tblComplaint data into tblReporter, as tblReporter does not have a Date Column, and tblComplaint does. I have tried having multiple SqlCommand statements for each select, that made no difference. I also tried having multiple DataRow (ie. dsnr, dsnr2, etc) and that made no difference. I also tried adding .Dispose to my data adapter and data set before moving to the second table, that also made no difference. Can anyone suggest what I might be doing wrong?
"Missing the DataColumn 'Date' in the DataTable 'tblReporter' for the SourceColumn 'Date'."
So I'm assuming the problem is that it's still trying to insert the tblComplaint data into tblReporter, as tblReporter does not have a Date Column, and tblComplaint does. I have tried having multiple SqlCommand statements for each select, that made no difference. I also tried having multiple DataRow (ie. dsnr, dsnr2, etc) and that made no difference. I also tried adding .Dispose to my data adapter and data set before moving to the second table, that also made no difference. Can anyone suggest what I might be doing wrong?
VB.NET:
Dim dcb As New SqlCommandBuilder(da)
Dim cmd As New SqlCommand
Dim dsnr As DataRow
Dim con As New SqlConnection("my server info")
dsnr = ds.Tables("tblComplaint").NewRow
cmd = New SqlCommand("SELECT * FROM tblComplaint", con)
dsnr.Item(0) = DBNull.Value
dsnr.Item(1) = txtDate.Text
dsnr.Item(2) = cmbReason.SelectedValue
dsnr.Item(3) = txtRecBy.Text
dsnr.Item(4) = txtRepBy.Text
dsnr.Item(5) = txtRepPh.Text
dsnr.Item(6) = txtRelated.Text
dsnr.Item(7) = txtComNotes.Text
dsnr.Item(8) = cmbMaterial.SelectedValue
dsnr.Item(9) = txtAdjNotes.Text
dsnr.Item(10) = txtCleanNotes.Text
inc = rowcount
ds.Tables("tblComplaint").Rows.Add(dsnr)
da.SelectCommand = cmd
da.Update(ds, "tblComplaint")
dsnr = ds.Tables("tblReporter").NewRow
cmd = New SqlCommand("SELECT * FROM tblReporter", con)
dsnr.Item(0) = txtRepPh.Text
dsnr.Item(1) = txtRepBy.Text
dsnr.Item(2) = txtRepAdd.Text
ds.Tables("tblReporter").Rows.Add(dsnr)
da.SelectCommand = cmd
da.Update(ds, "tblReporter")
dsnr = ds.Tables("tblOwner").NewRow
cmd = New SqlCommand("SELECT * FROM tblOwner", con)
dsnr.Item(0) = txtOPhone.Text
dsnr.Item(1) = txtOwner.Text
dsnr.Item(2) = txtOAdd.Text
dsnr.Item(3) = ds.Tables("tblComplaint").Rows(inc).Item(0)
ds.Tables("tblOwner").Rows.Add(dsnr)
da.SelectCommand = cmd
da.Update(ds, "tblOwner")
Last edited: