|
-
Oct 12th, 2009, 06:47 PM
#1
Thread Starter
Addicted Member
passing parameters to a stored procedure
I am confused about how to pass parameters to a stored procedure. The stored procedure is written in sql server 2005 and the code is in vb.net.
I have included the sub that I am working on. I know that my use of parameters is wrong. Can someone explain what I should do?
Code:
Public Sub AddRecipe()
Using myDBconnection As New SqlConnection(setConnstring)
Using SQLcmd As New SqlCommand()
SQLcmd.Connection = myDBconnection
SQLcmd.CommandType = CommandType.StoredProcedure
SQLcmd.CommandText = "CreateRecipe"
SQLcmd.Parameters.Add("Name", NVarChar)
End Using
End Using
End Sub
-
Oct 12th, 2009, 06:59 PM
#2
Re: passing parameters to a stored procedure
Here is a good example on how to use StoredProcedures in .Net.
-
Oct 12th, 2009, 07:06 PM
#3
Re: passing parameters to a stored procedure
There are essentially two ways to add a parameter to a command and they are the same whether you're executing a stored procedure or inline SQL. If you're calling ExecuteScalar, ExecuteReader or ExecuteNonQuery on the command or if you're executing it as the SelectCommand of a DataAdapter by calling Fill then you will normally want to set the parameter value when you add the parameter, e.g.
vb.net Code:
myCommand.Parameters.AddWithValue("@ParamName", paramValue)
There's no need to specify the type or size of the parameter because that's inferred from the value.
If you're executing the command as the DeleteCommand, InsertCommand or UpdateCommand of a DataAdapter by calling Update then you'll want to specify the source column for the parameter from the DataTable being saved, e.g.
vb.net Code:
myCommand.Parameters.Add("@ParamName", SqlDbType.NVarChar, 50, "SourceColumnName")
In this case you need to specify the type of the parameter and the size for those types that require it.
-
Oct 12th, 2009, 07:33 PM
#4
Thread Starter
Addicted Member
Re: passing parameters to a stored procedure
-
Oct 12th, 2009, 07:58 PM
#5
Thread Starter
Addicted Member
Re: passing parameters to a stored procedure
Can someone point me to resources on the syntax for stored procedures in sql server 2005. Its been a while since I have written a stored procedure and I am rusty.
I also need resources on how to pass an array of values all of the same data type to this stored procedure.
thanks,
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
|