Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:38:55+00:00 2026-05-27T20:38:55+00:00

I am new in asp.net and working on the data grid view in asp.net.i

  • 0

I am new in asp.net and working on the data grid view in asp.net.i have written the following code for inserting and updating the columns in grid view.the grid is showing the data very well,but when i am trying to edit any row in the grid then it is throwing an Exception:

System.NullReferenceException: Object reference not set to an instance of an object: in the following line:

string UpdateQuery = string.Format("UPDATE tbl_PaperRateList set rate=" + rate1.Text + " where companyId=" + company_id.Text + " and paperId=" +paper_id.Text+ "");


SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["con"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindGridData();
    }
}

protected void gridRateList_RowEditing(object sender, GridViewEditEventArgs e)
{
    gridRateList.EditIndex = e.NewEditIndex;
    BindGridData();
}

protected void gridRateList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
    gridRateList.EditIndex = -1;
    BindGridData();
}
#endregion

#region  Binding the RateList Grid
public void BindGridData()
{

    {
        conn.Open();
        SqlCommand cmdCompanyId = new SqlCommand("Select max(companyId) from tbl_PaperRateList", conn);
        int c_id = Convert.ToInt32(cmdCompanyId.ExecuteScalar());

        using (SqlCommand comm = new SqlCommand("select p.paperId,"
           + "p.Rate,pm.PaperName from tbl_PaperRatelist p,tbl_papermaster pm where p.paperId=pm.paperId and p.companyId=" + c_id + "", conn))
        {
            SqlDataAdapter da = new SqlDataAdapter(comm);
            DataSet ds = new DataSet();
            da.Fill(ds);
            gridRateList.DataSource = ds;
            gridRateList.DataBind();
        }
    }
}
#endregion

#region    /*Updating the Row in Grid View*/
protected void gridRateList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

    string s = gridRateList.DataKeys[e.RowIndex].Value.ToString();

    Label company_id = (Label)gridRateList.Rows[e.RowIndex].FindControl("CompanyId");
    Label paper_id = (Label)gridRateList.Rows[e.RowIndex].FindControl("paperId");
    TextBox rate1 = (TextBox)gridRateList.Rows[e.RowIndex].FindControl("txtRate");
    string UpdateQuery = string.Format("UPDATE tbl_PaperRateList set rate=" + rate1.Text + " where companyId=" + company_id.Text + " and paperId=" +paper_id.Text+ "");


    gridRateList.EditIndex = -1;
    BindGridData(UpdateQuery);

}
#endregion

#region    Bind the Gridview after updating the row
private void BindGridData(string Query)
{
    string connectionstring = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(connectionstring))
    {
        conn.Open();
        SqlCommand cmdCompanyId = new SqlCommand("Select max(companyId) from tbl_PaperRateList", conn);
        int cid = Convert.ToInt32(cmdCompanyId.ExecuteScalar());
        using (SqlCommand comm = new SqlCommand(Query +
                ";select p.paperId,"
+ "p.Rate,pm.PaperName from tbl_PaperRatelist p,tbl_papermaster pm where p.paperId=pm.paperId and p.companyId=" + cid + "", conn))
        {
            SqlDataAdapter da = new SqlDataAdapter(comm);
            DataSet ds = new DataSet();
            da.Fill(ds);
            gridRateList.DataSource = ds;
            gridRateList.DataBind();
        }
    }
}
#endregion
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:38:56+00:00Added an answer on May 27, 2026 at 8:38 pm

    Did u declared globally or assigned null value to the variable..?

    like this string UpdateQuery="";

    Check the rate1.Text,company_id.Text ,paper_id.Text properties getting values or not.

    Debug the Function BindGridData(string Query) the error happening there i think. check the parameters of that function. some parameters getting null value that’s what the Exception is coming. check it out.

    Hope this may helpful….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the ASP.NET grid view. It displays 3 columns with 1 row for each,
I have a grid in asp.net, inside the asp.net i am binding data as
I am fairly new to ASP.NET MVC and working on a small project in
I've been working with ASP.NET(WebForm) for a while, but new to ASP.NET MVC. From
I am new to C#.Working in ASP.NET 3.5 ( C# 3.0). What are the
I am relatively new to website design and specifically working in ASP.NET, i am
I am fairly new to C# and ASP.NET. I am working on an existing
I have a new asp.net mvc project and i am trying to figure out
I am working in ASP .net 2.0. I am a learner. I have a
We've just brought up a new ASP.NET page that is showing a strange error.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.