Solved

Clear Dataset

Posted on 2007-04-05
2
609 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to Get total minutes between two hours 4 45
Red error squiggly on vb.net 7 27
Convert an ASPX page into PDF 7 27
Get the selected ValueMember of Combobox 5 23
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

22 Experts available now in Live!

Get 1:1 Help Now