The problem is most likely with the
@id
parameter value.
In your
Page_Load
method, you use the value from the querystring parameter
Code
. In your
Button1_Click
method, you use the value from
ViewState
. At no point in the posted code have you initialized the
ViewState
value.
The simplest option would be to use the querystring in both methods:
protected void Page_Load(object sender, EventArgs e)
{
using (var connection = new SqlConnection("YOUR CONNECTION STRING HERE"))
using (var command = new SqlCommand("SELECT title FROM ooo WHERE id = @id", connection))
{
command.Parameters.AddWithValue("@id", Request.QueryString["code"]);
connection.Open();
TextBox1.Text = Convert.ToString(command.ExecuteScalar());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (var connection = new SqlConnection("YOUR CONNECTION STRING HERE"))
using (var command = new SqlCommand("UPDATE ooo SET title = @title WHERE id = @id", connection))
{
command.Parameters.AddWithValue("@title", TextBox1.Text);
command.Parameters.AddWithValue("@id", Request.QueryString["code"]);
connection.Open();
command.ExecuteNonQuery();
}
}