I am trying to use a stored procedure from SQL in VB.Net to add a row to the Product table. Here is the stored procedure:
I am creating the command in VB.Net with this code:
I keep getting an error saying:
Parameter1 is not a parameter for procedure add_product
I am new to stored procedures in VB.Net so Im sure it is some silly mistake. If anyone could help that would be great.
VB.NET:
CREATE PROCEDURE add_product
(
@name char,
@wholesaler int,
@price money,
@number_in_stock int,
@type char
)
AS
INSERT INTO Product ([name], wholesalerID, price, number_in_stock, type)
VALUES (@name, @wholesaler, @price, @number_in_stock, @type)
I am creating the command in VB.Net with this code:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] command [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlCommand
command.Connection = obj_conn
command.CommandType = CommandType.StoredProcedure
command.CommandText = "dbo.add_product"
[/SIZE]
Dim sql_param_name As New SqlParameter
sql_param_name.ParameterName = "@name"
sql_param_name.SqlDbType = SqlDbType.Char
sql_param_name.Direction = ParameterDirection.Input
sql_param_name.Value = txt_product_name.Text
Dim sql_param_wholesalerID As New SqlParameter
sql_param_wholesalerID.ParameterName = "@wholesaler"
sql_param_wholesalerID.SqlDbType = SqlDbType.Int
sql_param_wholesalerID.Direction = ParameterDirection.Input
sql_param_wholesalerID.Value = id
Dim sql_param_price As New SqlParameter
sql_param_wholesalerID.ParameterName = "@price"
sql_param_wholesalerID.SqlDbType = SqlDbType.Money
sql_param_wholesalerID.Direction = ParameterDirection.Input
sql_param_wholesalerID.Value = CDbl(txt_product_price.Text)
Dim sql_param_stock As New SqlParameter
sql_param_wholesalerID.ParameterName = "@number_in_stock"
sql_param_wholesalerID.SqlDbType = SqlDbType.Int
sql_param_wholesalerID.Direction = ParameterDirection.Input
sql_param_wholesalerID.Value = CInt(txt_product_price.Text)
Dim sql_param_type As New SqlParameter
sql_param_type.ParameterName = "@type"
sql_param_type.SqlDbType = SqlDbType.Char
sql_param_type.Direction = ParameterDirection.Input
sql_param_type.Value = cbo_product_type.Text
command.Parameters.Add(sql_param_name)
command.Parameters.Add(sql_param_wholesalerID)
command.Parameters.Add(sql_param_price)
command.Parameters.Add(sql_param_stock)
command.Parameters.Add(sql_param_type
I keep getting an error saying:
Parameter1 is not a parameter for procedure add_product
I am new to stored procedures in VB.Net so Im sure it is some silly mistake. If anyone could help that would be great.