cheruvannoor
Member
- Joined
- Aug 23, 2005
- Messages
- 13
- Programming Experience
- Beginner
i want to get format for updating a field in vb.net.i am using sql as database.my code is given below
conn = New SqlConnection
conn.ConnectionString = "data source=localhost;initial catalog=CARGO;user id=sa;pwd="
conn.Open()
myconn = New SqlCommand
myconn.Connection = conn
query = "select * from agent"
myconn.CommandText = query
myreader = myconn.ExecuteReader()
myconn = New SqlCommand
myconn.Connection = conn
query = "update Agent set agentId = '" & Txtkey.Text & "',agentdate='" & Format(dtp.Value, "MM/dd/yyyy") & "',agentname= '" & Txtname.Text & "',agentadd1= '" & Txtadd1.Text & "',agentadd2= '" & Txtadd2.Text & "',agentadd3= '" & Txtadd3.Text & "',agentphone= '" & Txtphone.Text & "',agentfax= '" & Txtfax.Text & "',agentemail= '" & Txtemail.Text & "',agentiata= '" & Txtiata.Text & "',agentac= '" & Txtac.Text & "'"
myconn.CommandText = query
myconn.ExecuteNonQuery()
MsgBox("updated")
my error message is
"An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: There is already an open DataReader associated with this Connection which must be closed first."
conn = New SqlConnection
conn.ConnectionString = "data source=localhost;initial catalog=CARGO;user id=sa;pwd="
conn.Open()
myconn = New SqlCommand
myconn.Connection = conn
query = "select * from agent"
myconn.CommandText = query
myreader = myconn.ExecuteReader()
myconn = New SqlCommand
myconn.Connection = conn
query = "update Agent set agentId = '" & Txtkey.Text & "',agentdate='" & Format(dtp.Value, "MM/dd/yyyy") & "',agentname= '" & Txtname.Text & "',agentadd1= '" & Txtadd1.Text & "',agentadd2= '" & Txtadd2.Text & "',agentadd3= '" & Txtadd3.Text & "',agentphone= '" & Txtphone.Text & "',agentfax= '" & Txtfax.Text & "',agentemail= '" & Txtemail.Text & "',agentiata= '" & Txtiata.Text & "',agentac= '" & Txtac.Text & "'"
myconn.CommandText = query
myconn.ExecuteNonQuery()
MsgBox("updated")
my error message is
"An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: There is already an open DataReader associated with this Connection which must be closed first."