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

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()

Tq bro....it works.....bump for u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.