【发布时间】:2013-10-12 11:51:51
【问题描述】:
我正在使用 PIC 32 控制器的 post 功能获取 URL。
就像 www.example.com/Default.aspx?x=12&y=23
我想做的是,当我得到 URL 时,我想将 x 和 y 的值存储到 SQL Server 中。
我在我的系统上使用 IIS 服务器启动了一个 .aspx。 aspx页面的编码是..
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Sample Configuration Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>IP Address:</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>MAC Address:</td>
<td>
<asp:TextBox ID="TxtUserName" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Save"
onclick="Button1_Click" />
</form>
</body>
</html>
请指导我。
数据将使用以下C#代码存储在数据库中,
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO tblRegistration1 (IP, MAC) VALUES "
+ " (@IP_Address,@MAC_Address)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[6];
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new SqlParameter("@IP_Address", SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@MAC_Address", SqlDbType.VarChar, 50);
param[0].Value = IP_Address;
param[1].Value = MAC_Address;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
public string GetConnectionString()
{
//sets the connection string from your web config file "ConnString" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
}
在计算机浏览器上使用时一切正常。 但是来自 PIC32 的帖子没有执行。我不知道如何处理返回到包含 IP 和 MAC 详细信息的 IIS 服务器的 URL。 在我的应用程序中,我从计算机的 PIC32 平台获得这些数据。
我希望我已经说清楚了。
【问题讨论】:
标签: asp.net sql-server query-string pic32