Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Mark H
Starting Member
6 Posts |
Posted - 2011-01-25 : 12:24:09
|
| This code is written in VWD 2010 express. This code is trying to add one row of five columns to the table KDistrictBridge. It doesn't do it.I got a message about declaring a scalar variable @EeID. Looking at forums, it appeared that I should write EeID=?. And so I made the change. (see first dim statement)Now I get a message "Incorrect syntax near ?".Does anyone know how to write the code to put one row of five columns in a table? That what I am actually trying to do. When I can do that, then I will try to get an array copied into KDisctBridge. But first things first.Many thanks for your help. ' Ddataset is defined at start of Sub Button1_Click() Dim strKDisctBridge As String = "SELECT * FROM KDisctBridge WHERE 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 End Sub |
|
|
|
|
|
|
|