接受asp中的发布数据并插入sql server [英] accept post data in asp and insert into sql server
本文介绍了接受asp中的发布数据并插入sql server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是回答了我的问题,并添加了一些其他脚本来将所有内容组合在一起
I just re did my question and added a few other scripts needed to pull everything together
这是我用来接收帖子并将数据推送到SQL Server(如果重要的2008)的小脚本: 建议后的更新2:
This is the small script I am using to receive the post and push the data into the SQL Server (2008 if that matters): UPDATE 2 after suggestions:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myConn As SqlConnection = New SqlConnection("Integrated Security=false;Data Source=.;Initial Catalog=DOMAIN_NAME;UserID=user;Password=password")
myConn.Open()
Dim sqlstring As String = " INSERT INTO sean.local (etype, latitude, longtitude, phone) VALUES ('" + Request.Form("type") + "','" + Request.Form("latitude") + "','" + Request.Form("longtitude") + "','" + Request.Form("phone") + "')"
Dim cmd As SqlCommand = New SqlCommand(sqlstring, myConn)
cmd.ExecuteNonQuery()
myConn.Close()
Response.Redirect(Request.RawUrl, True)
Response.Write("1 record added")
End Sub
</script>
这是我的创建表脚本
CREATE TABLE local
(
P_Id int PRIMARY KEY IDENTITY,
etype varchar(255) NOT NULL,
latitude varchar(255),
longtitude varchar(255),
phone varchar(255)
)
这是我用来测试的表格
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>A Web Page</title>
</head>
<body>
<BR></BR>
<form action="http://www.mydomain.com/script.asp" method="post">
<h1>Form Test</h1>
Phone:<BR></BR><input type="text" name="phone"/>
<BR></BR>
type:<BR></BR><input type="text" name="type"/>
<BR></BR>
lat:<BR></BR><input type="text" name="latitude"/>
<BR></BR>
lng:<BR></BR><input type="text" name="longtitude"/>
<BR></BR>
<input type="submit" name="submit" value="Submit Data"/>
</form>
</body>
</html>
可能很小,但我真的没有其他想法...谢谢.
It might be something small but I really have no other ideas...thank you.
推荐答案
主要是VB,只需切换到它即可
It's mostly VB, just switch to it
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myConn As SqlConnection = New SqlConnection("Integrated Security=false;Data Source=.;Initial Catalog=DOMAIN_NAME;UserID=abc;Password=123")
myConn.Open()
Dim sqlstring As String = " INSERT INTO sean.local (etype, latitude, longtitude, phone) VALUES ('" + Request.Form("type") + "','" + Request.Form("latitude") + "','" + Request.Form("longtitude") + "','" + Request.Form("phone") + "')"
Dim cmd As SqlCommand = New SqlCommand(sqlstring, myConn)
cmd.ExecuteNonQuery()
myConn.Close()
Response.Redirect(Request.RawUrl, True)
Response.Write("1 record added")
End Sub
</script>
如果您在C#中需要它,请通过以下命令运行它: http://wiki.sharpdevelop. net/Code%20Converter.ashx
If you need it in C#, run it through this: http://wiki.sharpdevelop.net/Code%20Converter.ashx
这篇关于接受asp中的发布数据并插入sql server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文