我创建了该过程,但是我不知道如何在Visual Studio中运行它
这在SQL中;
create procedure ekleSstores
@storeid as int,
@storename as varchar(50),
@phone as varchar(25),
@email as varchar(255),
@street as varchar(255),
@city as varchar(255),
@state as varchar(10),
@zipcode as varchar(5)
as
begin
set IDENTITY_INSERT sales.stores ON
insert into sales.stores(store_id,store_name,phone,email,street,city,state_,zip_code)
values(@storeid,@storename,@phone,@email,@street,@city,@state,@zipcode)
set IDENTITY_INSERT sales.stores OFF
end
如何在我的代码中运行此过程?在Visual Studio上
作为示例,其中connectionString
是数据库的连接字符串,下面的所有parameters
都是您要传递的实际参数:
using (var conn = new SqlConnection(connectionString))
{
using (var command = new SqlCommand("ekleSstores", conn))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@storeid", storeid));
command.Parameters.Add(new SqlParameter("@storename", storename));
command.Parameters.Add(new SqlParameter("@phone ", phone));
command.Parameters.Add(new SqlParameter("@email", email));
command.Parameters.Add(new SqlParameter("@street", street));
command.Parameters.Add(new SqlParameter("@city ", city));
command.Parameters.Add(new SqlParameter("@state ", state));
command.Parameters.Add(new SqlParameter("@zipcode", zipcode));
conn.Open();
command.ExecuteNonQuery();
}
}