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();
}
}
猜你喜欢
- 本文实例讲述了PHP笛卡尔积实现算法。分享给大家供大家参考,具体如下:<?php$arr = array(array(1,3,4,5)
- 网上学习了的两个新方法,代码非常之简洁。看来,不是只要实现了基本功能就能交差滴,想要真的学好python还有很长的一段路呀方法一:是利用ma
- 0. 学习目标在诸如单链表、双线链表等普通链表中,查找、插入和删除操作由于必须从头结点遍历链表才能找到相关链表,因此时间复杂度均为O(n)。
- Python字符串问题在arcpy中版本为 python2.x在QGIS中版本为 python2.x 或者 python3.xpython2
- 写在前面额、、、最近开始学习机器学习嘛,网上找到一本关于机器学习的书籍,名字叫做《机器学习实战》。很巧的是,这本书里的算法是用Python语
- 在opencv中,特征检测、描述、匹配都有集成的函数。vector<DMatch> bestMatches;用来存储得到的匹配点
- 上一篇相关文章python_tkinter弹出对话框创建需要的可以参考一下1.fledialog对话框示例:askopenfilename(
- 1 前言Simhash的算法简单的来说就是,从海量文本中快速搜索和已知simhash相差小于k位的simhash集合,这里每个文本都可以用一
- 方法1:1.安装requests_toolbelt依赖库#代码实现def upload(self): login_
- 由于工作需要,所以前一阵子将IE升级到了8.0,结果今天发现出现一个问题,eWebEditor的在线编辑器不好用了,仔细想想,肯定是IE8搞
- 一.FUNCTION: 在sqlserver2008中有3中自定义函数:标量函数/内联表值函数/多语句表值函数,首先总结下他们语法的异同点:
- 原图代码 src = cv2.imread("28.png") gray_src = cv2.c
- 今天在测试一个pytorch代码的时候显示显存不足,但是这个网络框架明明很简单,用CPU跑起来都没有问题,GPU却一直提示out of me
- 在网上查了部分资料但是发现粘上去的代码都存在问题,无奈只好自己修改了一下,代码如下: 如下代码能正常运行,都是网上查找资料最后拼凑总结出来的
- 本文将结合实例给大家演示如何使用ASP读取一个目录结构(及包含的文件信息)。演示页面中遍历显示了代码吾爱站点上若干目录文件夹——其中包含它们
- 今天看到everything搜索速度秒杀windows自带的文件管理器,所以特地模仿everything实现了文件搜索以及打开对应文件的功能
- 前言为什么做出这个?就是有时候从网上下载的资料中的pdf有水印,看着不舒服。比如说我从网上下载的试卷,然后去打印店打印,打印之后水印看着很不
- 一、Array数组的更改array数组中修改的API示例如下://创建大量相同元素的数组//创建有10个String类型元素的数组,并且每个
- 树树(Tree)是n(n≥0)个节点的有限集。在任意一棵树中:(1)有且仅有一个特定的称为根(Root)的节点;(2)当n>1
- 在.net 1.1中我们要实现压缩这一功能,一般都是用open source的SharpZipLib 或者调用