后台代码:
protected
void
Button1_Click(
object
sender, EventArgs e)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
int rowsAffected;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
SqlParameter[] parameters =
{
new SqlParameter("@title",TextBox1.Text),
new SqlParameter("@content", TextBox2.Text)
};
sdh.RunProcedure("[AddNew]", parameters, out rowsAffected);
![](/Images/OutliningIndicators/InBlock.gif)
Response.Write("OK!");
}
类的调用方法:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <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)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
using (SqlConnection connection = new SqlConnection(strConn))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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
)
人生最笨的事就是骑着驴找驴了,今天自己终于做了一次。
最后存储过程用了一个RunProcedure方法简单完成了。
组长在基类中都写好方法了,我不仔细研究,还傻傻的自己去创造~~~~~~