I encountered an error when trying to connect my project to a live database. The error message stated: the name ‘textbox’ does not exist in the current context. How can I resolve this issue?
Below is the aspx.cs code that I used for the connection, which resulted in the error:
using System.Data.SqlClient;
public partial class index : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ("Data Source=.SQLEXPRESS;AttachDbFilename=C:Users SOLO Desktop DesHomeWeb App_Data Database.mdf;Integrated Security=True;Encrypt=False;User Instance=True");
con.Open();
}
protected void btn3_click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into signup " + " (fname)values(@fname)", con);
cmd.Parameters.AddWithValue("@fname", textbox.text);
}
}
The following HTML code defines the textbox used in my aspx coding window:
<td><input type="text" placeholder="First Name" class="textbox1" id="textbox" /></td>