update coding for visual studio with database connection
plz provide me coding for update????
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Mar 26, 2014, 3:01 AM
To read the connection string into your code, use the ConfigurationManager class.
string connStr = ConfigurationManager.
ConnectionStrings["connect"].ConnectionString;
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
string name = gvDetails.DataKeys[e.RowIndex].Values["Name"].ToString();
TextBox city = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("city");
con.Open();
SqlCommand cmd = new SqlCommand("update Employee_Details set City='" + city.Text +"',name='" + name.Text + "' where UserId=" + userid, con);
cmd.ExecuteNonQuery();
con.Close();
lblresult.ForeColor = Color.Green;
lblresult.Text = username + " Details Updated successfully";
gvDetails.EditIndex = -1;
BindEmployeeDetails();
}
In Web config File
<connectionStrings> <add name="connect" connectionString="server=servername;database=myDb;
uid=myUser;password=myPass;" />
connectionStrings>