您的位置:首页 > 数据库

做项目时写的数据库操作类。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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: