标签:response 提交 string lag get ati client 程序 处理程序
添加用户模版,直接展示即可
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form method="post" action="add.ashx">
<table>
<tr>
<td>EmpName</td>
<td><input type="text" value="" name="EmpName"/></td>
</tr>
<tr>
<td>EmpAge</td>
<td><input type="text" value="" name="EmpAge"/></td>
</tr>
<tr>
<td>DelFlag</td>
<td><input type="text" value="" name="DelFlag"/></td>
</tr>
<tr>
<td cospan="2"><input type="submit" value="添加数据" /></td>
</tr>
</table>
</form>
</body>
</html>
POST提交处理页面add.ashx页面负责处理数据添加
<%@ WebHandler Language="C#" Class="add" %>
using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.IO;
public class add : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
string ConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(ConnStr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "insert into employee(empname,empage,delflag)values(@empname,@empage,@delflag)";
cmd.Connection = conn;
cmd.Parameters.Add("@empname",SqlDbType.VarChar);
cmd.Parameters.Add("@empage", SqlDbType.Int);
cmd.Parameters.Add("@delflag", SqlDbType.Int);
cmd.Parameters["@empname"].Value = context.Request.Form["EmpName"];
cmd.Parameters["@empage"].Value = context.Request.Form["EmpAge"];
cmd.Parameters["@delflag"].Value = context.Request.Form["DelFlag"];
conn.Open();
if (cmd.ExecuteNonQuery() > 0)
{
context.Response.Redirect("UserList.ashx");
}
else
{
context.Response.Redirect("error.htm");
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
标签:response 提交 string lag get ati client 程序 处理程序
原文地址:http://www.cnblogs.com/zhaodachao/p/6108113.html