Javascript 我试图在sql server中存储数据,但遇到了一个错误,我不知道如何修复
我正在尝试将用户名、电子邮件和他们的消息存储在我的联系人页面上。当我运行我的网站,进入联系人页面,在联系人表单中键入所有详细信息,然后单击发送按钮(发送按钮称为submitBtn)时,我得到了您可以在下图中看到的错误 错误消息: c代码:此c代码用于发送按钮Javascript 我试图在sql server中存储数据,但遇到了一个错误,我不知道如何修复,javascript,c#,asp.net,Javascript,C#,Asp.net,我正在尝试将用户名、电子邮件和他们的消息存储在我的联系人页面上。当我运行我的网站,进入联系人页面,在联系人表单中键入所有详细信息,然后单击发送按钮(发送按钮称为submitBtn)时,我得到了您可以在下图中看到的错误 错误消息: c代码:此c代码用于发送按钮 protected void submitBtn_Click(object sender, EventArgs e) { try { //Create the conecti
protected void submitBtn_Click(object sender, EventArgs e)
{
try
{
//Create the conection string and open the conn
SqlConnection conne = new SqlConnection(ConfigurationManager.ConnectionStrings["Fasthosts_MMConnectionString"].ConnectionString);
//Open the connection string
conne.Open();
//Get all the values from the text boxes etc and pass them over to the DB
string insertQuery = "insert into Contact(UserName, Email, Message) " +
"values(@UserName, @Email, @Message)";
SqlCommand com = new SqlCommand(insertQuery, conne);
//Get values from the controls such as the text boxes and pass them over to the DB
com.Parameters.AddWithValue("@UserName", tbUserName.Text);
com.Parameters.AddWithValue("@Message", userMessage.Text);
com.Parameters.AddWithValue("@Email", userEmail.Text);
//This actually executes the query with the given values above.
com.ExecuteNonQuery();
//Dispose the connection string once the data has been passed over the DB
conne.Close();
}
catch (Exception problem)
{
//throw Exception ;
Response.Write("Error Message: " + problem.ToString());
throw;
}
}
html代码:
<div id="contactForm" class="contactForm">
<div id="formHeader" class="formHeader">
<h1 id="message">Contact Us :)</h1>
</div>
<div id="formBody" class="formBody">
<form action="homepage.aspx" method="POST" name="contactForm">
<div class="inputContainer">
<label for="userName">
<i class="fa fa-lg fa-fw fa-user"></i>
</label>
<asp:TextBox ID="tbUserName" placeholder="John Smith" runat="server"></asp:TextBox>
<!--<input name="name" id="userName" type="text" placeholder="John Smith">-->
</div>
<div class="inputContainer">
<label for="userEmail">
<i class="fa fa-lg fa-fw fa-envelope"></i>
</label>
<asp:TextBox ID="userEmail" placeholder="jsmith@domain.com" runat="server"></asp:TextBox>
</div>
<div class="inputContainer">
<asp:TextBox ID="userMessage" rows="10" placeholder="Enter your message" runat="server" Height="100px"></asp:TextBox>
</div>
<!--<input id="submitBtn1" class="submitBtn" type="submit" value="Send">-->
<asp:Button ID="submitBtn" Class="submitBtn" runat="server" Text="Send" OnClick="submitBtn_Click" />
</form>
</div>
在源代码中page指令的第一行中编写此代码
<%@ Page EnableEventValidation="false" %>
为什么将其标记为SQL Server?mybe,因为它与在SQL Server中存储数据有关。
<%@ Page EnableEventValidation="false" %>