Run two sql command together

kerek2

Member
Joined
Jan 18, 2009
Messages
9
Programming Experience
Beginner
Hi,

I already create connection to sql database and successfull. I need to know how to run two command together?...This is my problem:-

VB.NET:
Expand Collapse Copy
sqlcmd = New Sqlcommand ( "Select * from Staff_Main where Staff_id like '"&textbox1.text&"'",cn)

dr = sqlcmd.executereader

while dr.read()
label1.text = dr.item(1) 'item 1 is name

sqlcmd = new sqlcommand ("insert into smart.dbo.event(e_staff_name) values "+Lable1.text+',cn)

sqlcmd.executenonquesry

But nothing insert in my table...can anyone help me/..pls

tq
 
To be specific, your SQL for the INSERT command is incorrect. However, this is mainly being caused by not using parameterised queries - see the link in my signature.
 
Hi,

I already create connection to sql database and successfull. I need to know how to run two command together?...This is my problem:-

VB.NET:
Expand Collapse Copy
sqlcmd = New Sqlcommand ( "Select * from Staff_Main where Staff_id like '"&textbox1.text&"'",cn)

dr = sqlcmd.executereader

while dr.read()
label1.text = dr.item(1) 'item 1 is name

sqlcmd = new sqlcommand ("insert into smart.dbo.event(e_staff_name) values "+Lable1.text+',cn)

sqlcmd.executenonquesry

But nothing insert in my table...can anyone help me/..pls

tq

Run this as an executeNonQuery():

VB.NET:
Expand Collapse Copy
INSERT INTO event(e_staff_name) 
SELECT TOP 1 [B]name[/B] FROM staff_main WHERE staff_id LIKE @staffId

Read IntertiaM's link (or the PQ link in my sig, they go to the same place) first so you understand what the @staffId is

Also read the DNU link in my sig if youre using a file based database
 
Back
Top