0

Hi,

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

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

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by kerek2
0

Hi, you should open the connection cn.Open() and then cn.Close() also you have a problem and the insert statement you are calling label1.text as lable1.text.

besides that check your table and see what is the minimum parameters that you need to insert.

also i will create another connection call it conn

sqlcmd = New Sqlcommand ( "Select * from Staff_Main where Staff_id like '"&textbox1.text&"'",cn)
cn.Open()
dr = sqlcmd.executereader

while(dr.read())
{

sqlcmd = new sqlcommand ("insert into smart.dbo.event(e_staff_name) values '"+dr.GetString(1)+"'",conn)
conn.Open()
sqlcmd.executenonquesry
conn.Close()
}
dr.Close()
cn.Close()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.