也就是把反回了字符串 显示到table中
$("#btnSearch").click(function () {
$.post("CurrentStocklist.ashx", function (result) {
$(".table").append(result);
})
})
这样
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace UI
{
///
/// CurrentStockList1 的摘要说明
///
public class CurrentStockList1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
using (SqlConnection con = new SqlConnection("server =.;uid=sa;pwd=123;database=lt"))
{
string s = "select top 100 c.autoid,c.cWhCode,c.cinvCode,c.iQuantity,wh.cWhName,inv.cInvName"
+ " from currentStock c left join wareHouse wh "
+ " on c.cWhCode =wh.cWHCode left join inventory inv on c.cInvCode =inv.cInvCode ";
using (SqlDataAdapter ada = new SqlDataAdapter(s, con))
{
DataTable dt = new DataTable();
ada.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("" + dr["autoid"].ToString() + " ");
sb.Append("" + dr["cwhCode"].ToString() + " ");
sb.Append("" + dr["cWHName"].ToString() + " ");
sb.Append("" + dr["cInvCode"].ToString() + " ");
sb.Append("" + dr["cInvName"].ToString() + " ");
sb.Append("" + dr["iquantity"].ToString() + " ");
sb.Append(" ");
context.Response.Write(sb.ToString());
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
View Code
也可以通过传参数查询
$("#btnSearch").click(function () {
$.post("CurrentStocklist.ashx", { whNames: $("#txtWHNameS").val(), invNames: $("#txtInvNames").val() }, function (result) {
$(".table").append(result);
})
})
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace UI
{
///
/// CurrentStockList1 的摘要说明
///
public class CurrentStockList1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string whName = (context.Request["whNames"] ??"").ToString();
string invName = (context.Request["invNames"] ?? "").ToString();
using (SqlConnection con = new SqlConnection("server =.;uid=sa;pwd=123;database=lt"))
{
string s = "select c.autoid,c.cWhCode,c.cinvCode,c.iQuantity,wh.cWhName,inv.cInvName"
+ " from currentStock c left join wareHouse wh "
+ " on c.cWhCode =wh.cWHCode left join inventory inv on c.cInvCode =inv.cInvCode "
+"where wh.cWHName like '%"+whName+"%' and inv.cInvName like "+ "'%"+invName+"%'";
using (SqlDataAdapter ada = new SqlDataAdapter(s, con))
{
DataTable dt = new DataTable();
ada.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("" + dr["autoid"].ToString() + " ");
sb.Append("" + dr["cwhCode"].ToString() + " ");
sb.Append("" + dr["cWHName"].ToString() + " ");
sb.Append("" + dr["cInvCode"].ToString() + " ");
sb.Append("" + dr["cInvName"].ToString() + " ");
sb.Append("" + dr["iquantity"].ToString() + " ");
sb.Append(" ");
context.Response.Write(sb.ToString());
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}