我正在制作一个使用 asp.net 将信息发送到 mysql 服务器的网站。代码。我遇到的问题是,当我调试代码并启动页面时,出现以下错误:
我不知道为什么,我有这个错误。这是我的代码:
默认.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"%>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<form id="form1" runat="server">
<div>
<table width="300px" >
<tr>
<td>First Name</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td >Last Name</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>User Name</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Email Address</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="lblError" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
默认.aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string cnnString = "Server=localhost;Port=1111;Database=ci_series;Uid=asdfasdf;Pwd=*******";
MySqlConnection connection = new MySqlConnection(cnnString);
string cmdText = "INSERT INTO membership (first_name ,last_name ,username ,password ,";
cmdText += "email_address)VALUES (first_name ,last_name ,username ,password ,email_address);";
MySqlCommand cmd = new MySqlCommand(cmdText, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("?first_name", MySqlDbType.VarChar).Value = txtFirstName.Text;
cmd.Parameters.Add("?last_name", MySqlDbType.VarChar).Value = txtLastName.Text;
cmd.Parameters.Add("?username", MySqlDbType.VarChar).Value = txtUserName.Text;
cmd.Parameters.Add("?password", MySqlDbType.VarChar).Value = txtPassword.Text;
cmd.Parameters.Add("?email_address", MySqlDbType.VarChar).Value = txtEmail.Text;
connection.Open();
int result = cmd.ExecuteNonQuery();
lblError.Text = "Data Saved";
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
}
我该如何解决?“在当前上下文中不存在”是什么意思?提前致谢!