Results 1 to 5 of 5

Thread: [RESOLVED] Bug !

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved [RESOLVED] Bug !

    cant seem to spot the bug! Can anyone please?

    ---------------------------------------------------
    Using cmd1 As New SqlCommand(query, MyConn)

    cmd1.CommandType = CommandType.StoredProcedure

    ..................
    ..................

    cmd1.Parameters.Add("@ReturnErrorText", SqlDbType.NVarChar, (100))
    cmd1.Parameters("@ReturnErrorText").Direction = ParameterDirection.Output
    cmd1.Parameters.Add("@Success", SqlDbType.Int)
    cmd1.Parameters("@Success").Direction = ParameterDirection.Output

    MyConn.Open()
    cmd1.ExecuteNonQuery()
    cmd1.Parameters.Clear()
    If Not CStr(cmd1.Parameters("@ReturnErrorText").Value) = String.Empty Then 'if there's error messages from stored proc
    MessageBox.Show(CStr(cmd1.Parameters("@ReturnErrorText").Value))
    MyConn.Close()
    Exit Sub
    End If
    success = CInt(cmd1.Parameters("@Success").Value)
    'before clearing the parameters swap the value of @success to see if Commit transaction is executed
    cmd1.Parameters.Clear()

    If success = 1 Then
    MessageBox.Show("New School has been added SUCCESSFULLY.", " Success", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End If

    End Using
    Last edited by angelica; Sep 11th, 2008 at 10:30 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Bug !

    As always, you should have told us which line the error occurred on, otherwise we can only guess.

    I would assume that it is on the If statement just after this line:
    cmd1.Parameters.Clear()
    ..and if so, the reason for the occurring is pretty easy to work out (just check the help for .Clear).

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Bug !

    Ok si_the_geek,

    Found the bug, a double clear parameters!

    thanks
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Bug !

    What does a "double clear parameters" mean?

  5. #5
    Hyperactive Member
    Join Date
    Jan 2008
    Location
    Merseyside
    Posts
    456

    Re: Bug !

    Think it means she had

    Code:
    cmd1.Parameters.Clear()
    placed twice in the code

Posting Permissions

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



Click Here to Expand Forum to Full Width