|
-
Aug 6th, 2003, 05:41 AM
#1
Thread Starter
New Member
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()
-
Aug 6th, 2003, 05:52 AM
#2
Lively Member
-
Aug 6th, 2003, 05:58 AM
#3
Thread Starter
New Member
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
-
Aug 6th, 2003, 06:01 AM
#4
Lively Member
What returns cbCustomerID.Text
I suppose this is a combobox ? Does it return a value ?
-
Aug 6th, 2003, 06:04 AM
#5
Thread Starter
New Member
Yes I tested it, it returns either 1, 2 or 3 dependant on selection!
Thanks
Gary
-
Aug 6th, 2003, 06:06 AM
#6
Lively Member
Leave out once the output parameter in you SP and in your code... what happens then ?
-
Aug 6th, 2003, 06:08 AM
#7
Thread Starter
New Member
I get the same error?!?!?
-
Aug 6th, 2003, 06:11 AM
#8
Lively Member
you're sure you did comment out this : .Parameters.Add(prmTheIdentity)
?
-
Aug 6th, 2003, 06:13 AM
#9
Thread Starter
New Member
-
Aug 6th, 2003, 06:17 AM
#10
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|