我是 c#.net 新手。这是我的表格。
First Name: <asp:TextBox ID="f_name" runat="server"></asp:TextBox>
<asp:Button ID="btnInsertion" runat="server" Text="Insert"
OnClick="btnInsertion_Click" />
我需要帮助来解决 Visual Basic 中的这两个错误。这是我的 xxxx.aspx.cs,它给了我两个 CS0103 错误 -f_name 在上下文中不存在。-txtFname 在上下文中不存在。
protected void btnInsertion_Click(object sender, EventArgs e)
{
using (NpgsqlConnection connection = new NpgsqlConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString();
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "Insert into student_folio values(@f_name)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new NpgsqlParameter(@f_name, txtFname.Text));
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
txtFname.Text = ""; s
}
}