In grid view my Row doesnot updated nor deleted

Related searches

I have a grid view in which I want to apply CRUD operation. When I click on Update button it says:

System.NullReferenceException: Object reference not set to an instance of an object at new_OCRS.Admin.gvReportCrime_RowUpdating(Object sender, GridViewUpdateEventArgs e) "

When I click on delete button , it does not show any error but value is not deleted.

Here is my code

 protected void gvReportCrime_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
    try
    {

        using (MySqlConnection con = new MySqlConnection(connectionString))
        {
            con.Open();
            string query = "UPDATE reportcrime SET Name=@Name,Phone1=@Phone1,Phone1,Phone2=Phone2,Email=@Email,Gender=@Gender,City=@City,Address=@Address,CrimeType=@CrimeType,CrimeDetail=@CrimeDetail WHERE CNIC = @CNIC";
            MySqlCommand mscmd = new MySqlCommand(query, con);
            mscmd.Parameters.AddWithValue("@Name", (gvReportCrime.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@ContactNo.1", (gvReportCrime.Rows[e.RowIndex].FindControl("txtPhone1") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@ContactNo.2", (gvReportCrime.Rows[e.RowIndex].FindControl("txtPhone2") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@EmailAddress", (gvReportCrime.Rows[e.RowIndex].FindControl("txtEmail") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@Gender", (gvReportCrime.Rows[e.RowIndex].FindControl("txtGender") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@CityName", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCity") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@PostalAddress", (gvReportCrime.Rows[e.RowIndex].FindControl("txtAddress") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@CrimeType", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCrimeType") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@CrimeDetail", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCrimeDetail") as TextBox).Text.Trim());
            mscmd.Parameters.AddWithValue("@CNICNO",Convert.ToString(gvReportCrime.DataKeys[e.RowIndex].Value.ToString()));
            mscmd.ExecuteNonQuery();
            gvReportCrime.EditIndex = -1;
            BindData();

        }
    }

    catch (Exception ex)
    {
            Response.Write("" + ex);
    }

 }

 protected void gvReportCrime_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {

            using (MySqlConnection con = new MySqlConnection(connectionString))
            {
                con.Open();
                string query = "DELETE FROM reportcrime SET WHERE CNIC = @CNIC";
                MySqlCommand mscmd = new MySqlCommand(query, con);
                mscmd.Parameters.AddWithValue("@CNIC", Convert.ToString(gvReportCrime.DataKeys[e.RowIndex].Value.ToString()));
                mscmd.ExecuteNonQuery();
                BindData();

            }
        }
        catch (Exception ex)
        {
            Response.Write("" + ex);
        }
    }

Your AddWithValue parameters do not match your Update Query. For example, you have below

mscmd.Parameters.AddWithValue("@ContactNo.1",...)

But @ContactNo.1 is missing in your Update statement. Similarly there are others. You need to fix that.

Edit and Update Record in GridView in ASP.Net, Add TemplateField inside the Columns Collection that is used to display custom content in a data-bound control. Add an ItemTemplate in the� The GridView control in Asp.Net is useful for displaying large data in a tabular format. I have previously posted an article on how to insert new rows in database using a GridView. In this article however, I'll show you how a GridView control can be used to update (edit), delete and insert data in a remote SQL Server table.

i have changed my code , @skimad but still same error.
string query = "UPDATE reportcrime SET Name=@Name,Phone1=@Phone1,Phone2=@Phone2,Email=@Email,Gender=@Gender,City=@City,Address=@Address,CrimeType=@CrimeType,CrimeDetail=@CrimeDetail WHERE CNIC = @CNIC";
                    MySqlCommand mscmd = new MySqlCommand(query, con);
                    mscmd.Parameters.AddWithValue("@Name", (gvReportCrime.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@txtPhone1", (gvReportCrime.Rows[e.RowIndex].FindControl("txtPhone1") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@txtPhone2", (gvReportCrime.Rows[e.RowIndex].FindControl("txtPhone2") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@txtEmail", (gvReportCrime.Rows[e.RowIndex].FindControl("txtEmail") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@Gender", (gvReportCrime.Rows[e.RowIndex].FindControl("txtGender") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@City", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCity") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@Address", (gvReportCrime.Rows[e.RowIndex].FindControl("txtAddress") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@CrimeType", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCrimeType") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@CrimeDetail", (gvReportCrime.Rows[e.RowIndex].FindControl("txtCrimeDetail") as TextBox).Text.Trim());
                    mscmd.Parameters.AddWithValue("@CNIC",Convert.ToString(gvReportCrime.DataKeys[e.RowIndex].Value.ToString()));
                    mscmd.ExecuteNonQuery();

How i can update GridView in web page when i edit or delete or , but this changes not be shown in my gridview that time. i should again run my program that these changes be shown in my gridview. How i can update GridView� The data source control that the GridView control is bound to does not support delete operations, or there is no delete command defined for the data source. Examples The following example demonstrates how to use the DeleteRow method to programmatically delete a record in a GridView control.

The message "Object not set to instance of Object" means that you are trying to use an object which has not been initialized. That is, you either set it to null, or you never set it to anything at all. The runtime throwing a NullReferenceException always means the same thing: you are trying to use a reference.

Use a breakpoint in your method and check where the value is being null

Peoplesoft grid work record, Record of Employment on the Web (ROE Web) is a secure Web-based application created How to add edit delete update records in Grid view ASP. As per my knowledge; Page is not allowed to be saved when we select Main record as� Your delete code looks like this. Gridview1.DeleteRow(e.RowIndex); Gridview1.DataBind(); When you call Gridview1.DataBind() you will populate your gridview with the current datasource. So, it will delete all the existent rows, and it will add all the rows from CustomersSqlDataSource.

ROE Web – Registration and account management, Similarly, Service Canada will not share with your financial institution any personal View the list of participating Sign-In Partners After submitting the information on the Create my profile screen, you will be Please note that selecting a default address will not update the information recorded at CRA. how to delete the row from gridview in asp.net c#. Dear Frnds, Am displaying data in gridview by using sql datasource. and also from left side of gridview i have edit and delete links manually selected from grid properties.

ROE Web user guide, This user guide does not explain how to fill out a ROE form. My Organizations: redirects you to your Organizations page; Record of Employment: A user who does not have access to a folder will be unable to view or amend ROEs that updated when values are entered in the Pay Periods of Block 15C. Here Mudassar Ahmed Khan has explained a simple step by step tutorial with an example, how to perform CRUD operation in GridView i.e. Insert Edit Update and Delete in ASP.Net GridView using C# and VB.Net. TAGs: ASP.Net, AJAX, SQL Server, GridView

This Grid View is working, but I must update my Chome first. At 22 July 2020, it was still working perfectly. Hope in the days forward, it will be.Thanks Simone Marullo for this Google Meet Grid View (fix).

Comments
  • Code improved, grammar enhanced
  • please post the updated code with the fixes if you have done so that it is helpful to see what you have.
  • it is showing null references on this line " mscmd.Parameters.AddWithValue("@Name", (gvReportCrime.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim());"
  • You need to put a breakpoint on that line and see what is Null.