做项目时写的数据库操作类。SqlHelper.cs(五)
2009-07-12 23:08
459 查看
ExcuteSQL .aspx.cs(示例)
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12
13 public partial class ExcuteSQL : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19
20 protected void btnSql_Click(object sender, EventArgs e)
21 {
22 //获取要执行的Sql
23 string sql = txtSql.Text;
24
25
26 //定义对象的资源保存范围,一旦using范围结束,将释放对方的所占资源
27 using (SqlConnection conn = new SqlConnection(SqlHelper .ConnectionStringLocalTransaction ))
28 {
29 //打开连接
30 conn.Open();
31 //调用执行命令,最好一项没有参数,设置为null
32 SqlHelper.ExecuteNonQuery(conn ,CommandType .Text ,sql,null);
33
34 Response.Write("<font color='red'>操作成功。</Font>");
35 }
36 }
37 }
38
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12
13 public partial class ExcuteSQL : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19
20 protected void btnSql_Click(object sender, EventArgs e)
21 {
22 //获取要执行的Sql
23 string sql = txtSql.Text;
24
25
26 //定义对象的资源保存范围,一旦using范围结束,将释放对方的所占资源
27 using (SqlConnection conn = new SqlConnection(SqlHelper .ConnectionStringLocalTransaction ))
28 {
29 //打开连接
30 conn.Open();
31 //调用执行命令,最好一项没有参数,设置为null
32 SqlHelper.ExecuteNonQuery(conn ,CommandType .Text ,sql,null);
33
34 Response.Write("<font color='red'>操作成功。</Font>");
35 }
36 }
37 }
38
相关文章推荐
- 做项目时写的数据库操作类。SqlHelper.cs(六)
- 做项目时写的数据库操作类。SqlHelper.cs(一)
- 做项目时写的数据库操作类。SqlHelper.cs(二)
- 做项目时写的数据库操作类。SqlHelper.cs(三)
- 做项目时写的数据库操作类。SqlHelper.cs(四)
- Sqlhelper.cs--数据库操作类
- 为公司一个项目写的一个数据库操作类,使用了SQL Relay
- 利用SqlHelper.cs实现Web程序对数据库的增、删、改等操作
- 数据操作类 SQLHelper.cs
- 个人学习代码保存:例2.小项目的sql简单的数据库操作类
- 公共的数据库访问访问类 SqlHelper.cs
- 利用SqlHelper.cs实现Web程序与数据库的连接
- 数据操作类 SQLHelper.cs
- 利用SqlHelper.cs实现Web程序与数据库的连接
- 数据操作类 SQLHelper.cs
- 利用SqlHelper.cs实现Web程序与数据库的连接
- SqlServerHelper.cs数据库操作
- 利用SqlHelper.cs实现Web程序对数据库的增、删、改等操作
- 利用SqlHelper.cs实现Web程序与数据库的连接
- C#数据库编程 之 DbHelper数据操作类【DBHelper.CS】