Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataGrid Update Problem

Posted on 2004-08-23
6
Medium Priority
?
294 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 336 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 332 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 332 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

963 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