Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Update command is not working in gridview
    text
    copied!<pre><code>&lt; asp:GridView ID="GridView1" runat="server" Width="550px" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green" ShowFooter="True" EnableModelValidation="True" Height="183px" DataKeyNames="id" OnRowEditing="EditRecord" OnRowCancelingEdit="CancelRecord" OnRowUpdating="UpdateRecord" OnRowDeleting="DeleteRecord"&gt;' protected void UpdateRecord(object sender, GridViewUpdateEventArgs e) { string strConnString = ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(strConnString); SqlCommand com; GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; int autoid = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); TextBox tbranchname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tbbranchname"); TextBox tsemno = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tbsemno"); TextBox tscode = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tbscode"); TextBox tsname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tbsname"); TextBox tstype = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tbstype"); try { conn = new SqlConnection(strConnString); conn.Open(); string query = "UPDATE [Semester_Wise_Subject] SET branch_name=@branchname,sem_no=@semno,sname=@sname,scode=@scode,subject_type=@stype WHERE (id=@attid) "; // string query = "UPDATE Batches_Allocation SET batch_type=@batchtype,branch_name=@branchname,sem_no=@semno,stu_distribution=@studis WHERE (batch_year=@attid AND batch_name=@attid1) "; com = new SqlCommand(query, conn); com.Parameters.Add("@branchname", tbranchname.Text.ToString()); com.Parameters.Add("@semno", tsemno.Text.ToString()); com.Parameters.Add("@sname", tsname.Text.ToString()); com.Parameters.Add("@scode", tscode.Text.ToString()); com.Parameters.Add("@stype", tstype.Text.ToString()); com.Parameters.Add("@attid", autoid); // com.Parameters.Add("@attid1", tbatchname.Text.ToString()); n = com.ExecuteNonQuery(); lblMessageLine.Text = n + "" + "Record Updated successfully."; lblMessageLine.ForeColor = Color.Green; // Refresh the data GridView1.EditIndex = -1; BindData(); } catch (SqlException ee) { lblMessageLine.Text = ee.Message; lblMessageLine.Visible = true; lblMessageLine.ForeColor = Color.Green; } finally { // lblMessageLine.Text = n + "" + "Record Updated successfully."; // lblMessageLine.ForeColor = Color.Green; conn.Close(); conn.Dispose(); } } </code></pre> <p>Delete command is working but update is not working,,in my table "id" is p.k..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload