日期:2014-05-20  浏览次数:20392 次

请教如何执行insert的sqlserver存储过程!
我正在学习使用sqlserver的存储过程,向数据库中插入一条数据,我的数据表中就两项,
ticketID(自增),   ticketName
我写的存储过程:
CREATE   PROCEDURE   AddSpecialTicket   @zw   ticketName(200)   AS
insert   into   SpecialTicket   (ticketName)   values   (@ticketName)

请教我用c#+asp.net如何执行这条存储过程!我刚刚开始学习,看了许多书照着写就是不行(书上说用SqlDateAdapter),请详细的列出步骤!谢谢.

------解决方案--------------------
public DataSet ReturnDataSet(string proc, SqlParameter[] paramlist)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "AdsysConnectionString "].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = proc;
if (paramlist != null && paramlist.Length > 0)
{
foreach (SqlParameter param in paramlist)
{
cmd.Parameters.Add(param);
}
}
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
conn.Close();
return ds;

}

在实体类写个方法,直接把参数列表和存储过程名字进来就OK了,
------解决方案--------------------
以上这个是有返回的,这个没!~
public void ExeuteNoQuery(string proc, SqlParameter[] paramlist)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "AdsysConnectionString "].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = proc;

if(paramlist!=null && paramlist.Length> 0)
{
foreach(SqlParameter param in paramlist)
{
cmd.Parameters.Add(param);
}
}
cmd.ExecuteNonQuery();
conn.Close();

}