发送json-简单的传参查询和简单的sql查询
简单的传参查询并转化为json using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; namespace Maticsoft.Web.guanlian { public partial class guanlian : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int start = int.Parse(Request.QueryString["start"]); int over = int.Parse(Request.QueryString["over"]); Maticsoft.BLL.guanlian bll = new Maticsoft.BLL.guanlian(); DataSet dataSet = bll.GetListByPage("", "id", start, over); DataTable dt = dataSet.Tables[0]; StringBuilder Json = new StringBuilder(); //if (string.IsNullOrEmpty(jsonName)) // jsonName = dt.TableName; Json.Append("{\"list\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Type type = dt.Rows[i][j].GetType(); Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); // return Json.ToString(); Response.Write(Json.ToString()); } } } 简单的sql查询 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using LTP.Accounts; namespace Maticsoft.Web.guanlian { public partial class guanlian : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //int start = int.Parse(Request.QueryString["start"]); //int over = int.Parse(Request.QueryString["over"]); //Maticsoft.BLL.guanlian bll = new Maticsoft.BLL.guanlian(); //DataSet dataSet = bll.GetListByPage("", "id", start, over); string sql = "select * from guanlian"; DataSet dataSet = DbHelperSQL.Query(sql); DataTable dt = dataSet.Tables[0]; StringBuilder Json = new StringBuilder(); //if (string.IsNullOrEmpty(jsonName)) // jsonName = dt.TableName; Json.Append("{\"list\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Type type = dt.Rows[i][j].GetType(); Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); // return Json.ToString(); Response.Write(Json.ToString()); } } } 简单的sql语句加传参 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using LTP.Accounts; namespace Maticsoft.Web.guanlian { public partial class guanlian : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //int start = int.Parse(Request.QueryString["start"]); //int over = int.Parse(Request.QueryString["over"]); string user = Request.QueryString["user"]; //Maticsoft.BLL.guanlian bll = new Maticsoft.BLL.guanlian(); //DataSet dataSet = bll.GetListByPage("", "id", start, over); string sql = "select * from guanlian where uer = '"+user+"' "; DataSet dataSet = DbHelperSQL.Query(sql); DataTable dt = dataSet.Tables[0]; StringBuilder Json = new StringBuilder(); //if (string.IsNullOrEmpty(jsonName)) // jsonName = dt.TableName; Json.Append("{\"list\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Type type = dt.Rows[i][j].GetType(); Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); // return Json.ToString(); Response.Write(Json.ToString()); } } }
简单的传参添加
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using LTP.Accounts; namespace Maticsoft.Web.guanlian { public partial class guanlian : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //int start = int.Parse(Request.QueryString["start"]); //int over = int.Parse(Request.QueryString["over"]); //Maticsoft.BLL.guanlian bll = new Maticsoft.BLL.guanlian(); //DataSet dataSet = bll.GetListByPage("", "id", start, over); //string sql = "delete from guanlian where uer = '"+user+"' "; //DataSet dataSet = DbHelperSQL.Query(sql); // DataTable dt = dataSet.Tables[0]; //StringBuilder Json = new StringBuilder(); string uer = Request.QueryString["uer"]; string goup = Request.QueryString["goup"]; string visty = Request.QueryString["visty"]; Maticsoft.Model.guanlian txl = new Model.guanlian(); Maticsoft.BLL.guanlian bll = new BLL.guanlian(); txl.uer = uer; txl.goup = goup; txl.visty = visty; if (bll.Add(txl) > 0)//使用bll的添加方法 { Response.Write("{\"result\":\"0\"}"); } else { Response.Write("{\"result\":\"1\"}"); } //if (string.IsNullOrEmpty(jsonName)) // jsonName = dt.TableName; //Json.Append("{\"list\":["); //if (dt.Rows.Count > 0) //{ // for (int i = 0; i < dt.Rows.Count; i++) // { // Json.Append("{"); // for (int j = 0; j < dt.Columns.Count; j++) // { // Type type = dt.Rows[i][j].GetType(); // Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); // if (j < dt.Columns.Count - 1) // { // Json.Append(","); // } // } // Json.Append("}"); // if (i < dt.Rows.Count - 1) // { // Json.Append(","); // } // } //} //Json.Append("]}"); //// return Json.ToString(); //Response.Write(Json.ToString()); } } }
sql加传参删除
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using LTP.Accounts; namespace Maticsoft.Web.guanlian { public partial class guanlian : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //int start = int.Parse(Request.QueryString["start"]); //int over = int.Parse(Request.QueryString["over"]); //Maticsoft.BLL.guanlian bll = new Maticsoft.BLL.guanlian(); //DataSet dataSet = bll.GetListByPage("", "id", start, over); //string sql = "delete from guanlian where uer = '"+user+"' "; //DataSet dataSet = DbHelperSQL.Query(sql); // DataTable dt = dataSet.Tables[0]; //StringBuilder Json = new StringBuilder(); string uer = Request.QueryString["uer"]; //string goup = Request.QueryString["goup"]; //string visty = Request.QueryString["visty"]; //Maticsoft.Model.guanlian txl = new Model.guanlian(); //Maticsoft.BLL.guanlian bll = new BLL.guanlian(); //txl.uer = uer; //txl.goup = goup; //txl.visty = visty; string sql = "delete from guanlian where uer = '"+uer+"' "; int rows = DbHelperSQL.ExecuteSql(sql.ToString(), ""); //DataTable dt = dataSet.Tables[0]; //StringBuilder Json = new StringBuilder();
if (rows > 0)//使用bll的添加方法 { Response.Write("{\"result\":\"0\"}"); } else { Response.Write("{\"result\":\"1\"}"); } //if (string.IsNullOrEmpty(jsonName)) // jsonName = dt.TableName; //Json.Append("{\"list\":["); //if (dt.Rows.Count > 0) //{ // for (int i = 0; i < dt.Rows.Count; i++) // { // Json.Append("{"); // for (int j = 0; j < dt.Columns.Count; j++) // { // Type type = dt.Rows[i][j].GetType(); // Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); // if (j < dt.Columns.Count - 1) // { // Json.Append(","); // } // } // Json.Append("}"); // if (i < dt.Rows.Count - 1) // { // Json.Append(","); // } // } //} //Json.Append("]}"); //// return Json.ToString(); //Response.Write(Json.ToString()); } } }