Solved

DataGrid Update Problem

Posted on 2004-08-23
6
285 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now