Solved

Clear Dataset

Posted on 2007-04-05
2
617 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
ID: 18858610
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
ID: 18859379
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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