Solved

DataGrid Update Problem

Posted on 2004-08-23
6
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

617 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