Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Clear Dataset

Posted on 2007-04-05
2
Medium Priority
?
631 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
[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
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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

704 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