WB AJax Example 2 the second method

Source: Internet
Author: User

Foreground code unchanged, the background C # code needs to build a class page display effect is not changed

Using system;using system.collections.generic;using system.linq;using system.web;using System.Data;using system.data.sqlclient;///<summary>///DB Summary description///</summary>public class Db{public db () {////TODO: Add constructor logic here//} public string SqlDB (string database, String type, String sql) {string connstring = "server=.;        Database= "+ database +"; uid=sa;pwd=123 ";        SqlConnection conn = new SqlConnection (connstring); SqlCommand cmd = conn.        CreateCommand ();        Cmd.commandtext = SQL;        String Shuju = ""; Conn.        Open (); if (type = = "CX") {SqlDataReader _dr = cmd.            ExecuteReader (); while (_DR. Read ()) {for (int i = 0; i < _DR. FieldCount; i++) {Shuju + = _dr[i].                ToString () + "^"; } Shuju = Shuju. Substring (0, Shuju.                LENGTH-1);            Shuju + = "|"; } Shuju = Shuju. Substring (0, Shuju.   LENGTH-1);     } else {int a = cmd.            ExecuteNonQuery (); if (a > 0) {Shuju = "Success!"            "; } else {Shuju = "Failed!            "; }} conn.        Close ();    return Shuju; }}

The Select page will then change:

Using system.data;using System.data.sqlclient;public class Select:ihttphandler {public        void ProcessRequest ( HttpContext context) {        //Fetch value        string name = Context. request["Name"]. ToString ();        Use the method of the class        //Make an SQL statement        string sql = "Select *from Info where name like '%" + name + "% '";        function         db cmd = new db () inside the DB class;        The function requires three parameters to return a string of        Shuju = cmd. SqlDB ("MyDB", "CX", SQL);        Write the string out of        context. Response.Write (Shuju);        Context. Response.End ();          }     public bool IsReusable {        get {            return false;        }    }

  

WB AJax Example 2 the second method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.