Solved

DataGrid Update Problem

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

708 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

19 Experts available now in Live!

Get 1:1 Help Now