1
protected
void
Button1_Click(
object
sender, EventArgs e)
2![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
//获取要执行的命令
4
string sqlexec = TextBox1.Text;
5
SqlCommand cmd = new SqlCommand();
6
//定义对象资源保存的范围,一旦using范围结束,将释放对方所占的资源
7
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
8![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
9
//打开连接(51aspx.com)
10
conn.Open();
11
//调用执行方法,因为没有参数,所以最后一项直接设置为null
12
SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlexec, null);
13
Response.Write("<font color=red>操作完成!请检查数据库!</font>");
14
}
15
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
15
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
SqlHelper是非常方便的数据库操作函数,功能强大,使用起来非常简单,免去很多复杂的数据库操作的代码,在多层应用及面向对象开发中都有很多应用
![](http://www.51aspx.com/codeImg/348A.jpg)
![](http://www.51aspx.com/codeImg/348b.jpg)
![](http://www.51aspx.com/codeImg/348c.jpg)
SqlHelper源码带有详细的说明,示例中有51aspx原始的示例Sql语句
主要包括以下操作:
简单SQL语句(ExcuteSql)
带参数的简单SQL语句(ExcuteSQLParm)
简单存储过程 (ExcuteProc)
带参数的存储过程(ExcuteProcParm)
只返回一个字段 (ExcuteScalar)
返回数据集(ExcuteReader)
源码下载地址:/Files/liudao/51aspxSqlHelper_51aspx.rar
数据库中有示例数据及存储过程updateTable\updateTableByParm,大家可以自行修改测试,转载请保留51aspx作者信息,谢谢! 其中可笑之处,还请多多指点~~
也许很多高手觉得简单,但是我还是相信不会用SqlHelper的居多,希望能对大家有所帮助!