Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 stored procedure problem

Author  Topic 

shobapond
Starting Member

2 Posts

Posted - 2003-02-04 : 23:29:27
Can i use a stored procedure twice in my codes?

i'm trying to use a stored procedure to insert values but when it is going
to execute the second time it produces and error.. anybody has a solution
for this problem?

If CheckBox1.Checked = True Then
myConnection2.Open()
objCommand2.CommandText = "gb1_ans_insert"
objCommand2.CommandType = CommandType.StoredProcedure

case_id.Text
objCommand2.Parameters.Add("@qu_id", SqlDbType.Int).Value = "1"
objCommand2.Parameters.Add("@ans_des",SqlDbType.VarChar).Value
= "Uneventful"
objCommand2.Parameters.Add("@ans_id", SqlDbType.Int).Value =
"1"
objCommand2.Parameters.Add("@ans_response", SqlDbType.Int).Value
= "1"

objCommand2.ExecuteNonQuery()

ElseIf CheckBox1.Checked = False Then
MessageBox.Show("not checked")
End If

If CheckBox2.Checked = True Then

objCommand2.CommandText = "gb1_ans_insert"
objCommand2.CommandType = CommandType.StoredProcedure

objCommand2.Parameters.Add("@case_id", SqlDbType.VarChar).Value
= case_id.Text
objCommand2.Parameters.Add("@qu_id", SqlDbType.Int).Value = "1"
objCommand2.Parameters.Add("@ans_des", SqlDbType.VarChar).Value
= "HIE"
objCommand2.Parameters.Add("@ans_id", SqlDbType.Int).Value =
"2"
objCommand2.Parameters.Add("@ans_response", SqlDbType.Int).Value
= "1"
objCommand2.ExecuteNonQuery()

ElseIf CheckBox2.Checked = False Then

MessageBox.Show("not checked")

End If

myConnection2.Close()

Thanks in advance for your help

nr
SQLTeam MVY

12543 Posts

Posted - 2003-02-04 : 23:41:25
You only open the connection if CheckBox1.Checked = True
For the second query you will have to clear the parameters as they will still be bound to the command from the first exec

Do you have a transaction anywhere to make sure this doesn't half succeed?

You've posted on 2 of the 4 sites I'm monitoring at the moment - see if you can get the other 2 :).

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nr on 02/04/2003 23:46:27
Go to Top of Page

shobapond
Starting Member

2 Posts

Posted - 2003-02-05 : 01:28:17
Hi

Thanks a lot for your help been helpful to me!!!

BTW you in which 2 other forums ? ;)

cheers
Go to Top of Page
   

- Advertisement -