A stored procedure was created to update a database.
But, I don't know how to trigger it in code:
This is the example to create a dataset for Dropdownlist,
Dim da As New SqlDataAdapter(myCommand)
Dim ds AS DataSet = new DataSet() da.Fill(ds)
This way doesn't work for triggering the stored procedure for updating database
How to trigger the stored Procedure for updating the database in the code?
Thx.
You need to create a SqlCommand object - in the properties for this you can set it to be a stored procedure and set the text to be something like [dbo].sprocname - then need to give it a SqlConnection object for it to be able to access the database
eg:
using
(SqlConnection conSQL =newSqlConnection("YourConString")){
using (SqlCommand cmd =newSqlCommand()){
cmd.CommandText =
"[dbo].sprocname";cmd.CommandType = System.Data.
CommandType.StoredProcedure;cmd.Parameters =
newSqlParameterCollection(<this should match your sproc>);cmd.ExecuteNonQuery();
}
}
No comments:
Post a Comment