Results 1 to 10 of 10

Thread: Stored Procedure

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    8

    Question Stored Procedure

    Hi

    The code below seems to fail on Executing the query!

    Any ideas?

    Gary


    SP:
    CREATE PROCEDURE [spInsertOrder]

    (@customerID int,
    @theidentity int OUTPUT
    )

    AS
    INSERT INTO [costingSystem].[dbo].[Orders]
    ( [customerID],
    [dateOrdered])

    VALUES
    ( @customerID,
    getdate())

    Select theidentity = @@identity
    GO


    CODE:
    Dim prmCustomerID As New SqlParameter()
    Dim prmTheIdentity As New SqlParameter()

    Me.Cursor = System.Windows.Forms.Cursors.WaitCursor()

    objConn = New SqlConnection(myGlobals.Name())
    objConn.Open()
    Try
    With prmCustomerID
    .Direction = ParameterDirection.Input
    .SqlDbType = SqlDbType.Int
    .ParameterName = "@customerID"
    .Value = cbCustomerID.Text
    End With

    With prmTheIdentity
    .Direction = ParameterDirection.Output
    .SqlDbType = SqlDbType.Int
    .ParameterName = "@theIdentity"
    End With

    objCmd = New SqlCommand("spInsertOrder", objConn)

    With objCmd
    .Parameters.Add(prmCustomerID)
    .Parameters.Add(prmTheIdentity)
    .ExecuteNonQuery()
    End With
    MessageBox.Show("The newest Identity value is: " & prmTheIdentity.Value.ToString)
    Catch sqlEx As SqlException
    MessageBox.Show(sqlEx.ToString)
    Finally
    objConn.Close()
    objConn.Dispose()
    End Try

    Me.Cursor = System.Windows.Forms.Cursors.Default()

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    What error do you get ?

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    8
    System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'spInsertOrder' at System.Data.SqlClient.SqlCommand.ExecuteReader(Command Behavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    line 525!

    There is a wee bit more but i think I captured the best bits!

    Thanks

    Gary

  4. #4
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    What returns cbCustomerID.Text

    I suppose this is a combobox ? Does it return a value ?

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    8
    Yes I tested it, it returns either 1, 2 or 3 dependant on selection!

    Thanks

    Gary

  6. #6
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    Leave out once the output parameter in you SP and in your code... what happens then ?

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    8
    I get the same error?!?!?

  8. #8
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    you're sure you did comment out this : .Parameters.Add(prmTheIdentity)
    ?

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    8
    yip!

  10. #10
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    Maybe you can your sqlprofiler then you can check which query's been given towards sqlserver

    HTH

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