ajax.net 데이터베이스에 대한 삽입 실례

4438 단어
Default.aspx
 
  



   
    <br>       function data_insert()<br>       {<br>          var xmlhttp;<br>          if (window.ActiveXObject) {<br>              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");<br>          }<br>          else if (window.XMLHttpRequest) {<br>              xmlhttp = new XMLHttpRequest();<br>          }<br>          else {<br>              alert(" ajax, !");  <br>          }<br>          xmlhttp.onreadystatechange=function()<br>          {<br>               if (xmlhttp.readyState==4 && xmlhttp.status==200)<br>               {<br>                    alert("yeah!");<br>                }<br>          } <br>          var no, name;<br>          no = document.getElementById("TextBox1").value;<br>          name = document.getElementById("TextBox2").value;<br>          var url = "Default2.aspx?no=" + no + "&name=" + name;<br>          xmlhttp.open("get", url, true);<br>          xmlhttp.send(null);<br>       }</p> <p>   


   

   

        :

        :
       

        
        

   




Default.aspx.cs
 
  
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Button1.Attributes.Add("onclick", "date_insert()");
    }

}


Default2.aspx
 
  



   


   

   


                    ConnectionString=""
            DeleteCommand="DELETE FROM [tst] WHERE [no] = @no"
            InsertCommand="INSERT INTO [tst] ([no], [name]) VALUES (@no, @name)"
            SelectCommand="SELECT * FROM [tst]"
            UpdateCommand="UPDATE [tst] SET [name] = @name WHERE [no] = @no">
           
               
           

           
               
               
           

           
               
               
           

       


       


   

   




Default2.aspx.cs
 
  
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.InsertParameters["no"].DefaultValue = //www.jb51.net/wghost/archive/2011/12/01/Request.QueryString["no"].ToString();
        SqlDataSource1.InsertParameters["name"].DefaultValue = //www.jb51.net/wghost/archive/2011/12/01/Request.QueryString["name"].ToString();
        SqlDataSource1.Insert();
    }

}

좋은 웹페이지 즐겨찾기