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 8354873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:41:29+00:00 2026-06-09T09:41:29+00:00

I have a grid view in asp.net which I am populating like this: sda1

  • 0

I have a grid view in asp.net which I am populating like this:

     sda1 = new SqlDataAdapter("select * from tran_dtls where tc='" + tcdropDown.SelectedValue + "'and doc_no='" + DocNoTxt.Text + "'", con);
     build = new SqlCommandBuilder(sda1);
     sda1.Fill(ds);                      //ds is a data set
     GridView1.DataSource = ds;
     GridView1.DataBind();

I update the grid view by passing the ds to a new data table, adding a new row in datatable then again binding the datatable to the grid:

       dt = (DataTable)ViewState["myViewState"];
              dt = ds.Tables[0];
              dr = dt.NewRow();
              dr["TC"] = Session["TC"];
              dr["sr_no"] = Session["i"].ToString(); //I have more fields but for simplicity only displaying few
              dt.Rows.Add(dr);
              dt.AcceptChanges();
              ViewState["myViewState"] = dt;

              Session["gridRow"] = dt;

Everything is smooth uptil now ,but when I try to update the database(after inserting new entries in the dataset) it doesn’t work the save button code is below:

 protected void onSaveClick(object sender, EventArgs e)
    {


        dt = (DataTable)Session["gridRow"];// I am passing the data table in a session    as I am entering the new entry from a pop up window
        dt.GetChanges(DataRowState.Modified);


        sda1.Fill(dt);

        sda1.Update(dt);   
    }

Funny part is when I edit a the existing entry in dt it does edit(classic sql update) but it never insert any new entries which are added in the data table ,and it doesn’t even throw a error

  • 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-06-09T09:41:32+00:00Added an answer on June 9, 2026 at 9:41 am

    This line

    dt.AcceptChanges(); 
    

    marks all rows in the datatable as Unchanged.

    When you call

    dt.GetChanges(DataRowState.Modified); 
    

    you get only the rows modified after the AcceptChanges()

    Moreover, to get the rows Added to the database the correct statement will be

    dt.GetChanges(DataRowState.Added); 
    

    but, as I have said, this will return nothing due to the AcceptChanges() call.
    You should remove the AcceptChanges() statement.
    Also, I don’t think you need to call this in the logic of the save button

    sda1.Fill(dt);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET GridView which is populated from a SQL Server database. This
I am currently developing an ASP.net c# application. I have a grid view which
I have an ASP.NET DataTable which I am populating from another set of ASP:TextBox
I have an ASP.NET GridView which has columns that look like this: | Foo
I have a GridView in ASP.net which is filled from an SqlDataSource. one of
I have a telerik grid in an asp.net mvc3 (RAZOR) View. While designing I
I have an issue with having a asp.net Grid View loaded into a div
OK, so this is bugging me. I have a gridview in ASP.net which I've
I don't have grid view as I am working on asp.net MVC. So can
Hello Freinds I am new to this Asp.net MVC Control.. I have a page

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.