I wrote this code to solve your problem. It is really simple.
I wrote to add new rows to Access Database as I currently don't have Sql Server installed on my machine.
So just replace OleDb with Sql in this code.
Change your connection String.
And, replace the insert command with your Update Command and it will work.
protected void btn1_Click(object sender, EventArgs e)
{
Label1.Visible = false;
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%\\UpdatefromTB.accdb;Persist Security Info=False;");
string OleDbStatement = string.Empty;
OleDbStatement = "insert into UpdatefromTB (TBValue) values (\"" + TextBox1.Text + "\")";
try
{
connection.Open();
OleDbCommand cmd = new OleDbCommand(OleDbStatement, connection);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
string msg = "Insert Error:";
msg += ex.Message;
Label1.Visible = true;
Label1.Text = msg;
}
finally
{
connection.Close();
}
}
Mark this as Answer please because it is.
Thanks.