【发布时间】:2012-03-27 07:34:31
【问题描述】:
我刚刚重新回答了我的问题,并添加了一些其他脚本来整合所有内容
这是我用来接收帖子并将数据推送到 SQL Server 的小脚本(2008 如果重要的话): 建议后更新 2:
<%@ 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>
这可能有点小,但我真的没有其他想法……谢谢。
【问题讨论】:
-
“我想我正在将 VB 和 C# 混合在一起,我只是纠结和迷失,” - 以前从未听说过!
-
Dim varname As Type在 C# 中应该是Type varname;。 -
您的查询容易受到 sql 注入攻击。不要使用这样的字符串连接来构建查询。
-
我会调查一下,我真的很想先获得基本功能,然后再对我的数据进行清理......你对我缺少什么有任何想法吗?