I was programming on update of grid view using select link button. I have linked select to another form and put an update button.
This is my table
news_id \\ int \\ No \\ PRI \\Auto_increment
Name \\ varchar(500) \\ No
news_date \\Date \\ No
description \\Text \\ No
Status \\ int \\ No
created_date \\Date \\ No
This is my code:
protected void btnupdate_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
con.Open();
SqlCommand cmd = new SqlCommand();
string ssql;
ssql = "Update news where news_id=@news_id(";
ssql = ssql + "'" + Convert.ToString(txtname.Text) + "'";
ssql = ssql + ",'" + Convert.ToString(startdate) + "'";
ssql = ssql + ",'" + Convert.ToString(txtdescription.Text) + "'";
ssql = ssql + ",'" + Convert.ToString(drpstatus.SelectedValue) + "'";
ssql = ssql + ",'" + Convert.ToString(lblcreateddate.Text) + "'";
ssql = ssql + ")";
cmd.CommandText = ssql;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
BindUserDetails();
}
catch (Exception ex)
{
}
}
I don't want to use news_id because I have given it as auto increment and so the user can't update it. So in the query I have written it won't know from where to find the news.
Please help.