Sql Server Query Parameter For Copy Data Table To Another Table Form Listview Vb.net
I'm using VB.net 2013 and SQL Server Express. I want to copy data from the table that appears in the listview to the temporary table. But I got an error: Operator '&' is not d
Solution 1:
Comments and explanation in-line. Following LarsTech comments.
Dim SIMPAN AsString = "INSERT INTO TempEntriBiaya (Column1Name, Column2Name) Values (@Column1, @Column2);"'The Using...End Using blocks ensure that your ADO objects are closed and 'disposed event if there is an errorUsing cn AsNew SqlConnection("Your connection string")
'The command and parameters only need to be declared once'outside the loop, only the value of the parameters changeUsing cmd AsNew SqlCommand(SIMPAN, cn)
cmd.Parameters.Add("@Column1", SqlDbType.Int)
cmd.Parameters.Add("@Column2", SqlDbType.VarChar)
'Open the connection at the last possible moment
cn.Open()
ForEach itm As ListViewItem In ListViewMasterBiaya.CheckedItems
cmd.Parameters("@Column1").Value = itm.SubItems(0).Text
cmd.Parameters("@Column2").Value = itm.SubItems(1).Text
cmd.ExecuteNonQuery()
NextEndUsingEndUsingEDIT Use event ListView.ItemChecked
PrivateSub ListViewMasterBiaya_ItemChecked(sender AsObject, e As ItemCheckedEventArgs) Handles ListViewMasterBiaya.ItemChecked
'e.Item returns the ListViewItem that changed its checkIf e.Item.Checked = TrueThenDim SIMPAN AsString = "INSERT INTO TempEntriBiaya (Column1Name, Column2Name) Values (@Column1, @Column2);"'The Using...End Using blocks ensure that your ADO objects are closed and 'disposed event if there is an errorUsing cn AsNew SqlConnection("Your connection string")
Using cmd AsNew SqlCommand(SIMPAN, cn)
cmd.Parameters.Add("@Column1", SqlDbType.Int).Value = e.Item.SubItems(0)
cmd.Parameters.Add("@Column2", SqlDbType.VarChar).Value = e.Item.SubItems(1)
'Open the connection at the last possible moment
cn.Open()
cmd.ExecuteNonQuery()
EndUsingEndUsingEndIfEndSub
Post a Comment for "Sql Server Query Parameter For Copy Data Table To Another Table Form Listview Vb.net"