?
Solved

Dataset Update Question

Posted on 2005-04-03
2
Medium Priority
?
177 Views
Last Modified: 2010-04-23
i have a datagrid populated by a dataset called: "DS_Vendor1" - showing data from a table called "Vendor" - I recently asked a question here about updating and a helpful member, after giving me the perfect answer - suggested that it would be easier to work directly with the dataset (he was right) - in any case - here is my question: I am currently using the below code to add a new entry - it's working exactly as I want it to - what i'd like to be able to do is have 2 more similar routines that work just like the code below, but one needs UPDATE functionality and the other DELETE functionality

            '''what would this command be to do an update? i need to be able to pass it the id(primary key, autonumber) of the row i want to update
            '''same for delete - need to be able to give it the id(primary key, autonumber) of the record to delete
            Dim NewRow As DataRow = DS_Vendor1.Vendor.NewRow

            '''and on UPDATE set all the values for the row with that id to the below text field values
            '''similar to what i'm doing below for adding new values
            NewRow.Item("Vendor_Name") = Trim(v_name.Text)
            NewRow.Item("Vendor_Addr1") = Trim(v_addr1.Text)
            NewRow.Item("Vendor_Addr2") = Trim(v_addr2.Text)
            NewRow.Item("Vendor_City") = Trim(v_city.Text)
            NewRow.Item("Vendor_State") = Trim(v_state.Text)
            NewRow.Item("Vendor_Zip") = Trim(v_zip.Text)
            NewRow.Item("Vendor_Phone") = Trim(v_phone.Text)
            NewRow.Item("Vendor_Fax") = Trim(v_fax.Text)
            NewRow.Item("Vendor_Contact") = Trim(v_contact.Text)
            NewRow.Item("Vendor_Email") = Trim(v_email.Text)
            NewRow.Item("Vendor_Website") = Trim(v_website.Text)

            '''Then the code that actually executes the UPDATE/DELETE...just as this one does for ADD
            DS_Vendor1.Vendor.Rows.Add(NewRow)

sorry to be asking such a basic question, but there are just TOO many ways to do the same thing in vb.net : - ) - i really like the way the above code works (found the example right here on EE), and im' thinking there has to be a very simple one-liner where u pass the id of the record u want updated and then assign the values....and same for delete, but time is running short and i haven't found it yet -
0
Comment
Question by:friskyweasel
[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
2 Comments
 
LVL 14

Accepted Solution

by:
amyhxu earned 2000 total points
ID: 13694410
To update:
'Suppose you have a textbox called txtID where user can enter ID. (Maybe you use a comboboxto list the ID) just get the primary key value to Find() method
Dim dRow As DataRow = DS_Vendor1.Vendor.Rows.Find(Convert.ToInt32(txtID.Text))  'find the row currently displayed
dRow("Vendor_Name") = v_name.Text.Trim
dRow("Vendor_Addr1") = v_addr1.Text.Trim
...


To Delete:
'Use the same code as in update method to find the current row
Dim dRow As DataRow = DS_Vendor1.Vendor.Rows.Find(Convert.ToInt32(txtID.Text))
dRow.Delete()

When finally it's time to update the database, use
myDataAdapter.Update(DS_Vendor1.Vendor)
0
 

Author Comment

by:friskyweasel
ID: 13694505
Your suggestion worked perfectly. Thanks a lot!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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