怎样在.NET中通过SqlCommand调用存储过程?
我想通过VS.NET的SqlCommand调用 SQL Server2000中的存储过程,但如果该存储过程是有返回结果集的,我该怎么调用,用哪个方法?谢谢 问题点数:50、回复次数:6Top
1 楼kentis(小张->老张)回复于 2003-09-04 16:09:13 得分 0
我现在知道可以用ExecuteReade方法来执行它,可是我不想用DataReader,我想用DataRable,有什么办法?Top
2 楼qimini(循序渐进)回复于 2003-09-04 16:27:09 得分 25
SqlDataAdapter adp=new SqlDataAdapter();
SqlCommand com=new SqlCommand();
com.Connectoin=new SqlConnection(strConnectionString);
com.CommandType=StoredProcedure;
com.CommandText=The Name of your StoredProcedure;//你的存储过程名字
adp.SelectCommand=com;
adp.Fill(your DataSet);Top
3 楼asam2183(三山)回复于 2003-09-04 16:29:03 得分 5
SqlCommand oCmd = new SqlCommand("parem", oConn);
...
SqlDataAdapter oDa=new SqlDataAdapter(oComm);
oDs.Fill(oDs);Top
4 楼cnhgj(戏子) (没时间练太极)回复于 2003-09-04 16:31:24 得分 15
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
SqlCommand salesCMD = new SqlCommand("SalesByCategory", nwindConn);
salesCMD.CommandType = CommandType.StoredProcedure;
SqlParameter myParm = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15);
myParm.Value = "Beverages";
nwindConn.Open();
SqlDataReader myReader = salesCMD.ExecuteReader();
Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1));
while (myReader.Read())
{
Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1));
}
其中SalesByCategory为存储过程名称,@CategoryName为参数
Top
5 楼dahuzizyd(你就是我心中的女神)回复于 2003-09-04 16:34:12 得分 5
SqlCommand salesCMD = new SqlCommand("存储过程名", nwindConn);
salesCMD.CommandType = CommandType.StoredProcedure; //设置Command类型
Top
6 楼chinawn(动性忍心)回复于 2003-09-04 17:21:17 得分 0
简单就是最好Top




