温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SqlHelper源码及使用实例
当前文件:
SqlHelper/ExcuteSQLParm.aspx.cs,打开代码结构图
SqlHelper/ExcuteSQLParm.aspx.cs,打开代码结构图1using 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
//该源码下载自www.51aspx.com(51aspx.com) 14
15
public partial class ExcuteSQLParm : System.Web.UI.Page 16
{ 17
protected void Page_Load(object sender, EventArgs e) 18
{ 19
20
} 21
protected void Button1_Click(object sender, EventArgs e) 22
{ 23
//初始化参数 24
SqlParameter myparm = new SqlParameter(); 25
//获取参数的名字 26
myparm.ParameterName = txtparm.Text; 27
//设置变量的类型和长度 28
myparm.SqlDbType = SqlDbType.NVarChar; 29
myparm.Size = 20; 30
//获取参数的值 31
myparm.Value = txtvalue.Text; 32
//获取要执行的命令 33
string sql = txtsql.Text; 34
SqlCommand cmd = new SqlCommand(); 35
//定义对象资源保存的范围,一旦using范围结束,将释放对方所占的资源 36
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) 37
{ 38
//打开连接 39
conn.Open(); 40
//调用执行方法 41
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, myparm); 42
43
Response.Write("<font color=red>操作完成!请检查数据库!</font>"); 44
} 45
} 46
} 47





}
}