Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Posts
    8

    Unhappy Unanswered: stored procedure problem

    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.Va rChar).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

  2. #2
    Join Date
    Oct 2001
    Location
    England
    Posts
    426

    Cool

    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?


  3. #3
    Join Date
    Jan 2003
    Posts
    8
    Hi

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

    BTW you in which 2 other forums ?

    cheers

  4. #4
    Join Date
    Oct 2001
    Location
    England
    Posts
    426
    At the moment
    www.sqlteam.com
    www.dbforums.com
    www.experts-exchange.com
    http://msdn.microsoft.com/newsgroups/

    Sites I view varies depending on if anything interesting is happenning there but usually view sqlteam.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •