Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

asp. net question

Posted on 2003-02-26
6
Medium Priority
?
218 Views
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.
0
Comment
Question by:Leonid99
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dhymes
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 + "'";
               sqlAccountsAdapter.Fill(ds);
               if(!(ds.Tables["Accounts"].Rows.Count > 0))
               {
                    ds.Clear();
                    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();

                    ds.Tables["Accounts"].Rows.Add(anyRow);
                    sqlAccountsAdapter.Update(ds);


               }
0
 
LVL 1

Author Comment

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

Author Comment

by:Leonid99
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.
0
 
LVL 2

Accepted Solution

by:
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().

example..

private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
          {
               int rowToDelete = e.Item.ItemIndex;
               dsInfo.Tables[0].Rows[rowToDelete].Delete();
DataGrid1.Update();
               DataGrid1.DataBind();
          }
0
 
LVL 2

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

572 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