直接在库里创建,参考: //**************************************************************
// Stored Procedure ListBySubject_Sample
// CREATE procedure ListBySubject_Sample
// (
// @SubjectID Integer
// )
// AS
// SELECT top 5 BookID, BookTitle, Author, Price, Retail
// FROM Products
// where SubjectID = @SubjectID
// RETURN
//
// GO
//**************************************************************SqlDataReader GetSpecials_Procedure(SqlConnection currentConnection)
{
SqlDataReader myDataReader;
Object my_DBNull; try {
my_DBNull = Convert.DBNull; SqlDataReader myReader;
int subjectidin = 21;
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = currentConnection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "LISTBYSUBJECT_SAMPLE";
myCommand.Parameters.Add(new SqlParameter("@SubjectID",
SqlDbType.Int, 4, ParameterDirection.Input,
true,0,0,"",DataRowVersion.Default, my_DBNull) );
//set @SubjectID parameter value to 21 (Specials)
myCommand.Parameters[0].Value = subjectidin;
myDataReader = myCommand.ExecuteReader(); return (myDataReader);
}
catch (SqlException e) {
throw e;
}
}
// Stored Procedure ListBySubject_Sample
// CREATE procedure ListBySubject_Sample
// (
// @SubjectID Integer
// )
// AS
// SELECT top 5 BookID, BookTitle, Author, Price, Retail
// FROM Products
// where SubjectID = @SubjectID
// RETURN
//
// GO
//**************************************************************SqlDataReader GetSpecials_Procedure(SqlConnection currentConnection)
{
SqlDataReader myDataReader;
Object my_DBNull; try {
my_DBNull = Convert.DBNull; SqlDataReader myReader;
int subjectidin = 21;
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = currentConnection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "LISTBYSUBJECT_SAMPLE";
myCommand.Parameters.Add(new SqlParameter("@SubjectID",
SqlDbType.Int, 4, ParameterDirection.Input,
true,0,0,"",DataRowVersion.Default, my_DBNull) );
//set @SubjectID parameter value to 21 (Specials)
myCommand.Parameters[0].Value = subjectidin;
myDataReader = myCommand.ExecuteReader(); return (myDataReader);
}
catch (SqlException e) {
throw e;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货