在.NET中调用存储过程

来源:互联网 发布:清军战斗力 知乎 编辑:程序博客网 时间:2024/04/30 16:42

1.用SqlCommand和DataSet:
SqlConnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",connn);
cmd.CommandType=CommandType.StoreProcedure;

SqlDataAdapter dsCommand=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
dsCommand.Fill(ds);

2.用SqlCommand和SqlDataAdapter
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
Response.Write(dr.Item["Field"]);
}

转自: http://www.cg163.net/ithtm/id.aspid=9509.htm

原创粉丝点击