ajax.net对数据库的插入实例
发布时间:2024-01-18 01:15:01
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript">
function data_insert()
{
var xmlhttp;
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
alert("您的浏览器不支持ajax,请使用其他!");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("yeah!");
}
}
var no, name;
no = document.getElementById("TextBox1").value;
name = document.getElementById("TextBox2").value;
var url = "Default2.aspx?no=" + no + "&name=" + name;
xmlhttp.open("get", url, true);
xmlhttp.send(null);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
号码:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
姓名:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<input type="button" value="button" onclick="data_insert()"/>
</div>
</form>
</body>
</html>
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
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings: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">
<DeleteParameters>
<asp:Parameter Name="no" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="no" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="no" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</div>
</form>
</body>
</html>
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 = https://www.jb51.net/wghost/archive/2011/12/01/Request.QueryString["no"].ToString();
SqlDataSource1.InsertParameters["name"].DefaultValue = https://www.jb51.net/wghost/archive/2011/12/01/Request.QueryString["name"].ToString();
SqlDataSource1.Insert();
}
}


猜你喜欢
- 尾递归简介尾递归是函数返回最后一个操作是递归调用,则该函数是尾递归。递归是线性的比如factorial函数每一次调用都会创建一个新的栈(la
- 基于Vue的页面切换左右滑动效果,具体内容如下HTML文本页面:<template> <div id="app&
- 本文实例讲述了Python实现动态给类和对象添加属性和方法操作。分享给大家供大家参考,具体如下:动态给类和对象添加属性定义一个Person类
- var obj = document.getElementById("testSelect"); //定位idvar i
- 译者newstart写的简介:Ross Dawson所在的Future Exploration Network于2007年5月发布的web2
- <html> <head> <title>Untitled Document</title>
- 参数数量及其作用该函数共有两个参数,分别是key和scope。def get_collection(key, scope=None) Wra
- pip install命令默认是用的是python官方源,由于一些客观原因,连接速度很慢,甚至超时中断,到时很多模块安装不上,甚是苦恼!怎么
- 前言最近在工作经常会碰到对字符串进行去重操作,下面就给大家列出用Python如何处理的,话不多说了,来一起看看详细的介绍吧。比如说,要拿下面
- 今天给大家分享一下最新版阿里大于的短信验证码在node koa2的实现,还是有很多坑需要注意。首先需要在阿里云注册账号,并获取阿里云访问秘钥
- PyQt5是python中一个非常实用的GUI编程模块,功能十分强大。刚刚学完了Pyqt的编程,就迫不及待的写出了一个电子词典GUI程序。整
- Silverlight也算一个比较开放的技术。Button控件其实也是一些标准的Grid、Canvas、Rectangle、TextBloc
- 前言在对数据进行处理时我们常常会用到format与round函数。二者都能保留若干位小数,但在处理过程上稍有不同。不同之处返回类型不同:fo
- PyCaret 是一个开源、低代码的 Python 机器学习库,可自动执行机器学习工作流。它是一种端到端的机器学习和模型管理工具,可以以指数
- 基本代码from redis import *if __name__ == '__main__': sr = StrictR
- http://validator.w3.org/#validate_by_upload 在线校验网址点浏览,上次找到自己做的页面
- 在任何一个数据库中,查询优化都是不可避免的一个话题。对于数据库工程师来说,优化工作是最有挑战性的工作。MySQL开源数据库也不例外本站收录这
- ZeroClipboard.js是一个支持复制和粘贴的JavaScript插件,目前官方已经到2.x的版本了,但不支持IE9以下的浏览器,而
- 现在网页的设计都讲究整体统一风格,无论是网页的文字、图像,还是浏览器的滚动条都要求颜色和风
- 简介说明本文用示例介绍Vuex的五大核心之一:actions。官网Action | VuexAPI 参考 | Vuexactions概述说明