Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Case Modding > add record to table

Reply
Thread Tools

add record to table

 
 
mhh12 mhh12 is offline
Junior Member
Join Date: Jan 2011
Posts: 1
 
      01-22-2011
This code is trying to add one row of five columns to a table called KDistrictBridge. It doesn't do it.

I get a message about declaring a scalar variable @EeID. What about all the other variables? Is @EeID sczalar because I designated it as primary key? What else is wrong with this code? Many thanks for your help.

' Ddataset is defined at start of Sub Button1_Click()

Dim strKDisctBridge As String = "SELECT * FROM KDisctBridge WHERE EeID=@EeID "
Dim tblKDisctBridge As New SqlCommand(strKDisctBridge, Ddataset)
Dim sqlInsert As String = "INSERT INTO KDistrictBridge " & _
"(EeID,DdID,District,CcID,DisctSet) VALUES " & _
"(@EeID,@DdID,@District,@CcID,@DisctSet)"
Try
' make the data adapter
Dim da As New SqlDataAdapter
da.SelectCommand = New SqlCommand(strKDisctBridge, Ddataset)
' make and fill the KDisctBridge dataset
Dim ds As New DataSet
da.Fill(ds, "KDisctBridge")
' get the datatable out of the Ddataset list of tables
Dim dt As DataTable = ds.Tables("KDisctBridge")
' add a row to the table
Dim newrow As DataRow = dt.NewRow
newrow("EeID") = 1
newrow("DdID") = 2
newrow("District") = "Able"
newrow("CcID") = 3
newrow("DisctSet") = "Baker"
dt.Rows.Add(newrow)
' insert the new row
' create the command
Dim insertCmd As New SqlCommand(sqlInsert, Ddataset)
insertCmd.Parameters.Add(New SqlParameter("", "EeID"))
insertCmd.Parameters.Add(New SqlParameter("", "DdID"))
insertCmd.Parameters.Add(New SqlParameter("", "District"))
insertCmd.Parameters.Add(New SqlParameter("", "CcID"))
insertCmd.Parameters.Add(New SqlParameter("", "DisctSet"))
da.InsertCommand = insertCmd
da.Update(ds, "KDisctBridge")
Catch ex As SqlException
MsgBox("error at catch" & ex.ToString())
Console.WriteLine("Error: " & ex.ToString())
Finally
Ddataset.Close()
End Try
End Using
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net Web Controls 0 06-25-2006 01:30 PM
How to add a button to Modify, delete or add a new record to this code karenmiddleol@yahoo.com ASP General 2 10-04-2005 11:55 AM
How to add a button to Modify, delete or add a new record to this code karenmiddleol@yahoo.com ASP General 0 10-01-2005 07:21 AM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM



Advertisments