Update coding for visual studio with database connection
plz provide me coding for update????
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Munesh SharmaRank #174 · 13.9K reputationPosted Mar 25, 2014, 11:01 PM EDT
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>