Solved

DataGrid Update Problem

Posted on 2004-08-23
6
286 Views
Last Modified: 2012-06-27
Hi, When Updating the datagird the old values persist...any idees

Thanks


Code Snippet
++++++++++

private void Page_Load(object sender, System.EventArgs e)
            {
                  

                  if(!Page.IsPostBack)
                  {
                  sqlDataAdapter1.Fill(dataSet11);
                  DataGrid1.DataBind();
                  }

                  
                  
            }



            
            

            

            private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DataGrid1.EditItemIndex = e.Item.ItemIndex;
                  DataGrid1.DataBind();
            }

            private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
            DataGrid1.EditItemIndex = -1;
            DataGrid1.DataBind();
            }

            private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  int key = (int)DataGrid1.DataKeyField[e.Item.ItemIndex];
                  
                  TextBox tx;
                  tx = (TextBox) (TextBox)e.Item.Cells[3].Controls[0];
                  string val = tx.Text;

                  DataSet1.tbl_BSR_Report_ArchiveRow UpdateRow;
                  UpdateRow = dataSet11.tbl_BSR_Report_Archive.FindByID(key);

                  UpdateRow.CommentTech = "There was a problem";

                  sqlDataAdapter1.Update(dataSet11);
                  DataGrid1.EditItemIndex = -1;
                  DataGrid1.DataBind();
            }

            

      
      }
}
0
Comment
Question by:xy15973
6 Comments
 
LVL 5

Accepted Solution

by:
LindzK earned 84 total points
ID: 11868863
I know vb.net a lot better than c#.net but ..

The two things that would be missing in vb.net ( give it a try with your c# code ) and I thnk in c# also

are the fact that when you edit a dataset, you usually have to get it to accept the changes

 DataSet1.AcceptChanges();

Also at least in vb.net you have to reset the datasource, before doing the databind

 DataGrid1.datasource() = DataSet1.Tables(0);
 DataGrid1.DataBind();

 
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 83 total points
ID: 11870831
try this:

private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
          {
               int key = (int)DataGrid1.DataKeyField[e.Item.ItemIndex];
               
               TextBox tx;
               tx = (TextBox) (TextBox)e.Item.Cells[3].Controls[0];
               string val = tx.Text;
 
            string sql = "UPDATE Table1 SET myField1=\"" + val +
              " WHERE ID=" + key;

            OleDbCommand cmd = new OleDbCommand(sql, conn);
              cmd.ExecuteNonQuery();


             
               DataGrid1.EditItemIndex = -1;
               DataGrid1.DataBind();
          }
0
 
LVL 2

Assisted Solution

by:Shahankit
Shahankit earned 83 total points
ID: 11882882
Your code seems fine.. how did you declare your dataset?... you need to declare like :::

DataSet dataSet11 = New DataSet

Try If it works or not..

Cheers
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question