后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
int rowsAffected;
SqlParameter[] parameters = {
new SqlParameter("@title",TextBox1.Text),
new SqlParameter("@content", TextBox2.Text)
};
sdh.RunProcedure("[AddNew]", parameters, out rowsAffected);
Response.Write("OK!");
}
类的调用方法:{
int rowsAffected;
SqlParameter[] parameters = {
new SqlParameter("@title",TextBox1.Text),
new SqlParameter("@content", TextBox2.Text)
};
sdh.RunProcedure("[AddNew]", parameters, out rowsAffected);
Response.Write("OK!");
}
/// <summary>
/// 执行存储过程,返回影响的行数
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name="rowsAffected">影响的行数</param>
/// <returns></returns>
public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
using (SqlConnection connection = new SqlConnection(strConn))
{
int result;
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
//Connection.Close();
return result;
}
}
create proc AddNew
(
@title varchar(50),
@content varchar(50)
)
as
insert into News values(@title,@content)
(
@title varchar(50),
@content varchar(50)
)
as
insert into News values(@title,@content)
人生最笨的事就是骑着驴找驴了,今天自己终于做了一次。
最后存储过程用了一个RunProcedure方法简单完成了。
组长在基类中都写好方法了,我不仔细研究,还傻傻的自己去创造~~~~~~