Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert in gridview
    text
    copied!<p>HI please see the following code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class viewdutyslip : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); } } protected void LoadData() { SqlDataAdapter da = new SqlDataAdapter("select duty_slip_no, slip_date, company, guest, booked_by, car_no, driver_name, meter_start, DATEDIFF(Day,start_date,end_date), toll from add_duty_slip", con); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Label duty_slip_no = (Label)GridView1.Rows[e.RowIndex].FindControl("lbldutyslip"); SqlCommand cmd = new SqlCommand("delete from add_duty_slip where duty_slip_no='" + duty_slip_no.Text + "'",con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); GridView1.EditIndex = -1; LoadData(); lblMessage.Text = "Successfully Deleted"; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; LoadData(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label duty_slip_no = (Label)GridView1.Rows[e.RowIndex].FindControl("lbldutyslip"); TextBox slip_date = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdate"); TextBox company = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcompany"); TextBox guest = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtguest"); TextBox booked_by = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbooked"); TextBox car_no = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcarno"); TextBox driver_name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdrivername"); TextBox meter_start = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmeter"); TextBox toll = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txttoll"); SqlCommand cmd = new SqlCommand("update add_duty_slip set slip_date='"+slip_date.Text+"',company='"+company.Text+"',guest='"+guest.Text+"',booked_by='"+booked_by.Text+"',car_no='"+car_no.Text+"', driver_name='"+driver_name.Text+"',meter_start='"+meter_start.Text+"',toll='"+toll.Text+"' where duty_slip_no='"+GridView1.DataKeys[e.RowIndex].Values[0].ToString()+"'",con); con.Open(); cmd.ExecuteNonQuery(); GridView1.EditIndex = -1; con.Close(); lblMessage.Text = "Update Successfully"; } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; LoadData(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { } } </code></pre> <p>I want to Update my Gridview value. But it is giving an error "Object reference not set to an instance of an object".</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