Solved

Clear Dataset

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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