1. SqlConnection thisConnection = new SqlConnection();
thisConnection.Open(StrConn);
SqlCommand thisCommand = thisConnection.CreateCommand();
//命令类型为存储过程
thisCommand.CommandType = CommandType.StoredProcedure;
//存储过程名称
thisCommand.CommandText = "Ten Most Expensive Products";
//执行存储过程
SqlDataReader thisReader = thisCommand.ExecuteReader();
//显示结果
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["TenMostExpensiveProducts"], thisReader["UnitPrice"]);
}
2.
myCommand.CommandType=CommandType.StoredProcedure;
//添加输入查询参数、赋予值
myCommand.Parameters.Add("@Name",SqlDbType.VarChar);
myCommand.Parameters["@Name"].Value ="A";//添加输出参数
myCommand.Parameters.Add("@Rowcount",SqlDbType.Int);
myCommand.Parameters["@Rowcount"].Direction=ParameterDirection.Output;
myCommand.ExecuteNonQuery();
DataAdapter.SelectCommand = myCommand;if (MyDataSet!=null)
{
DataAdapter.Fill(MyDataSet,"table");
}