asp. net question

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-04-15
Hi, I have a page with a datagrid. the connection to the database is performed via sqldataadapter. i also added edit/update/cancel column. i have the problem with posting the data back to the database. to use sqldataadapter's update() method, i need to extract dataset from datagrid, and all the documentation i've found deals with invocation of sql update command in the on_update method of datagrid, while i want to do it via sqldataadapter. Please, help!
Regards, L.
Question by:Leonid99
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
  • 2
  • 2

Expert Comment

ID: 8029621
Below is a snippedt of code that will Insert a record, then call the Update methode for the Adapter. You can do the same thing by simply Doing a Select to populate the DataSet, modify the fields in your DataSet, then simply call Update using the Adapter.

Good luck

          private void btnRegister_Click(object sender, System.EventArgs e)
               // Insure this email doesn't already exist.
            MySalesEdge.AccountsDataSet ds = new MySalesEdge.AccountsDataSet();
               this.sqlSelectCommand1.CommandText = "Select * from Accounts where EmailAddress='" + this.txtEmailAddress.Text + "'";
               if(!(ds.Tables["Accounts"].Rows.Count > 0))
                    System.Data.DataRow anyRow = ds.Tables["Accounts"].NewRow();

               //     anyRow["AccountId"]          = 6;
                    anyRow["EmailAddress"]     = this.txtEmailAddress.Text;
                    anyRow["UserPassWord"]     = this.txtPassword.Text;
                    anyRow["FirstName"]          = this.txtFirstName.Text;
                    anyRow["LastName"]          = this.txtLastName.Text;
                    anyRow["MiddleName"]     = this.txtMiddleName.Text;
                    anyRow["Street"]          = this.txtStreet.Text;
                    anyRow["City"]               = this.txtCity.Text;
                    anyRow["State"]               = this.txtState.Text;
                    anyRow["PostalCode"]     = this.txtPostalCode.Text;
                    anyRow["CountryCode"]     = 0;
                    anyRow["Phone"]               = this.txtPhone.Text;
                    anyRow["CreditCardType"]= this.drpCreditCardType.SelectedItem.Text;
                    anyRow["CreditCardNo"]     = this.txtCreditCardNumber.Text;

                    string strYear = this.drpYear.SelectedItem.Text;
                    string strMonth = this.drpMonth.SelectedItem.Text;
                    System.DateTime dt = new System.DateTime(System.Convert.ToInt32(this.drpYear.SelectedItem.Text), System.Convert.ToInt32(this.drpMonth.SelectedItem.Text),1);
                    anyRow["ExperationDate"] = dt.ToLongDateString();
                    anyRow["CreationDate"] = System.DateTime.Now.ToLongTimeString();



Author Comment

ID: 8031637
I don't see what all this has to do with my question :)
Rephrasing the question

Author Comment

ID: 8031643
As a matter of fact, what I have to do is following: I have the fully configured SqlDataAdapter (with all 4 sql commands), and the datagrid. I know how to update the datagrid with the data from adapter, but can't do it in the opposite direction.

Accepted Solution

wiseguy_2112 earned 300 total points
ID: 8044906
Are you using the Delete, Insert and Edit events on teh datagrid?  You just edit whichever row the user changed, inserted or deleted and call Update().


private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
               int rowToDelete = e.Item.ItemIndex;

Expert Comment

ID: 8044913
Sorry, meant to point out that you do the updates on the DataSet, not the DataAdapter

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

800 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