I use the following code in ASP.NET 2.0 to update the database:
Dim myConnectionAsNew SqlClient.SqlConnection("server=local);uid=sa;pwd=xxx;database=Northwind")
Dim myCommandAsNew SqlClient.SqlCommand("dbo.spTralen_customer_save 'CACTU'", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myConnection.Open()
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
I get the following error message: "Could not find stored procedure..."
The sp is in the database and dbo is the owner of the sp and I'm logged in as sa as you can see above. It doesn't matter if I remove the "dbo." from the sql command, it still doesn't work. If I remove the parameter value 'CACTU' above I get an error message saying that the sp expects the parameter so the sp is obviously in the database.
Can someone please help me as soon as possible!
// Gato Gris
if CACTU is the value you want to place into your parameter try the following, set it up similiar to 1.1 way of doing this --
Dim myConnectionAsNew SqlClient.SqlConnection("server=local);uid=sa;pwd=xxx;database=Northwind")
Dim myCommandAsNew SqlClient.SqlCommand("dbo.spTralen_customer_save", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add (NewSqlParameter("@.ParameterName", Value of parameter))
myConnection.Open()
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
You need to add the parameter separately.
Dim myCommandAsNew SqlClient.SqlCommand("dbo.spTralen_customer_save", myConnection)
...
..
myCommand.Parameters.Add(New SqlParameter("@.paramName",SqlDbType.VarChar,50))
myCommand.Parameters("@.paramName").Value="CACTU"
myConnection.Open()
myCommand.ExecuteNonQuery
myConnection.close()
Notice I have used ExecutENonQuery instead of ExecuteReader. ExecuteReader returns a datareader while ExecuteNonQuery simply returns the rows effected. If your stored proc DOES return a result set and you'd like to retrieve the set then you'd use E..Reader. If you simply want to execute the stored proc, you'd use E..NonQuery. You can read up documentation regarding - ExecuteReader/ExecuteQuery/ExecuteScalar methods and use the appropriate one.
No comments:
Post a Comment