I have a modal pop up data from listview to update in SQL Database with an update button Click. Please help me with one example code to update the existing data in the database. My code is also provided.
protected void btnsubitemUpdate_Click(object sender, EventArgs e)
{
int SUBITEMNO = Convert.ToInt32(lvsubitem.SelectedDataKey);
string SUBITEMNAME = txtsubitemedit.Text.Trim();
txtsubitemedit.Text = SUBITEMNAME.ToUpper();
Update(SUBITEMNO, SUBITEMNAME);
}
private void Update(int Id, string Name)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_UpdateSubItemData", con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() > 0)
{
txtSubItemName.Text = "";
MessageBox1.ShowSuccess("Sucessfully Updated");
}
con.Close();
GetSubItem();
}
catch (Exception ex)
{
MessageBox1.ShowError(ex.Message);
con.Close();
}
}