Solved

Clear Dataset

Posted on 2007-04-05
2
605 Views
Last Modified: 2010-05-18
Hi Experts,

I have the following code: -

            Do Until Current_Record = MSFlexGrid1.Rows - 1
                Current_Record = Current_Record + 1
                If MSFlexGrid1.get_TextMatrix(Current_Record, 2) = Current_Supplier Then
                    PO_Line = PO_Line + 1
                    Total_Cost = 0
                    Total_Cost = CDbl(MSFlexGrid1.get_TextMatrix(Current_Record, 5)) * CDbl(MSFlexGrid1.get_TextMatrix(Current_Record, 3))
                    PO_Total_Cost = CStr(CDbl(PO_Total_Cost) + (CDbl(MSFlexGrid1.get_TextMatrix(Current_Record, 5)) * CDbl(MSFlexGrid1.get_TextMatrix(Current_Record, 3))))

                    Dim dr As DataRow = dstPurchaseOrder.Tables(0).NewRow()

                    dr("Item_Description") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 0), "'", "''")
                    dr("Stock_Code") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 1), "'", "''")
                    dr("Supplier") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 2), "'", "''")
                    dr("Lead_Time") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 6), "'", "''")
                    dr("Cost_Price") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 3), "'", "''")
                    dr("Qty") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 5), "'", "''")
                    dr("Line") = PO_Line
                    dr("PO_Number") = Replace(CStr(PO_Number), "'", "''")
                    dr("Total_Price") = Replace(MSFlexGrid1.get_TextMatrix(Current_Record, 4), "'", "''")

                    dstPurchaseOrder.Tables(0).Rows.Add(dr)

                End If

            Loop

What I’m trying to do is populate a dataset. I think I have made a mistake on Dim dr As DataRow = dstPurchaseOrder.Tables(0).NewRow() as I am not able to us dr.tables(“Purchase_Order”).clear before the loop. What code do I use to add a new row so that I can set the “Dim” variable at the beginning please.

Many Thanks
Lee
0
Comment
Question by:ljhodgett
  • 2
2 Comments
 
LVL 34

Expert Comment

by:Sancler
Comment Utility
Your Dim statement looks OK.  

What is it you are trying to do with

   dr.tables(“Purchase_Order”).clear

dr - that is, your DataRow - has a .Table property, which will return the datatable of which this is the .NewRow: but you know that, anyway.  But it doesn't have a .tables collection - which is what dr.tables(“Purchase_Order”) would be trying to access.  If "Purchase_Order" is one of the fields/columns in that datarow, you would access it - in the same way as you are doing the others - just with dr("Purchase_Order").  If you wanted to clear that (although, unless the column has its .DefaultValue set, in a new row it should be clear anyway) you would use dr("Purchase_Order") = "" or something similar.

If that's not enough to get you on the right road, can you please explain your objective in a bit more detail?

Roger
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
Comment Utility
I just re-read this, and perhaps I was being a bit thick.  Maybe the clue is in the question title "Clear Dataset" ;-)

If what you are wanting to do is clear the table before you start adding rows use this

     dstPurchaseOrder.Tables(0).Clear

or, if your table is called "Purchase_Order", you can refer to it by name

     dstPurchaseOrder.Tables("Purchase_Order").Clear

or, if its the only table in the dataset, or you are happy to clear them all

     dstPurchaseOrder.Clear

Roger
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now