problem in dataport

Hi, I have a query regarding dataport. I have a text(csv) file which looks like this No,Name,Address Item No,Quantity,Price Now i want to push 1st line to the customer table & 2nd line to the item table. Please help me in this regard. Thanks, Vikas S. Shettar

As Dataitem you use a table, it doesn’t matter which one. As DataportFields you use global Variables. And then you use a counter. In the OnAfterImportRecord-Trigger you increase the Counter. If the Counter is odd, you use the imported Data in the variables for input in Customer table, if the counter is even, you use it for the item table. Hope this helps, Frank

sir… i tried wht u said but its not inserting records in tables. i have to insert the records simlatanously into the two tables. first line must be inserted into customer and second line into item. can u explain me…

How do you test the Dataport? During Designmode (ctrl + R) oder have you closed it and started with the Run-Button in the Object-Desinger? Dataports only work correctly if you do it the second way!!! have a look at your post at There will be a code-example of how to do it. Regards, Frank

gvImportField1 Text gvImportField2 Text gvImportField3 Text gvImportLineCounter Integer gvCustomer Record Customer gvSalesPrice Record Sales Price gvImportCustNo Text Declare your Dataport “DataItem” to be either Customer or Item, but modify the DataItem properties to: AutoUpdate: False AutoInsert: False AutoReplace: False Assign these 3 fields as your DataPortFields. What will happen is, when importing, gvImportField1 will then either contain a Customer No OR Item No. Now, in the OnAfterImportRecord trigger of your DataItem, you must do the following: IF gvImportCounter = 1 THEN BEGIN gvImportedCustNo := ImportField1; IF NOT gvCustomer.GET(gvImportField1) THEN BEGIN //Insert Customer gvCustomer.INIT; gvCustomer.“No.” := COPYSTR(gvImportField1, 1, 20); gvCustomer.VALIDATE(Name, COPYSTR(gvImportField2, 1, 30)); gvCustomer.Address := gvImportField3; gvCustomer.INSERT; END; gvImportCounter += 1; END ELSE IF gvImportCounter = 2 THEN BEGIN gvSalesPrice.RESET; gvSalesPrice.SETRANGE(gvSalesPrice.“Sales Type”::Customer); gvSalesPrice.SETRANGE(gvSalesPrice.“Sales Code”, gvImportCustNo); gvSalesPrice.SETRANGE(gvSalesPrice.“Item No.”, gvImportField1); IF NOT gvSalesPrice.FIND(’-’) THEN BEGIN //Insert Sales Price gvSalesPrice.INIT; gvSalesPrice.“Item No.” := COPYSTR(ImportField1, 1, 20); gvSalesPrice.“Sales Type” := gvSalesPrice.“Sales Type”::Customer; gvSalesPrice.“Sales Code” := gvImportCustNo; gvSalesPrice.INSERT; END; gvImportCounter := 1; END; problem… 1. it is not entering into first loop… 2. if 1st loop is executed then 2nd loop is not executing…why?

hi, based on the problems you said, are you sure that you have declared your counter as a global variable? also you have to set your counter to have a value of 1, either on OnPreDataitem or OnPreDataport. Bobby

You have to put gvImportCounter := 1; in the OnPreDataport-Trigger. This should do the work. Frank

Your problem should be solved by now. How many lines do you have in your file ? Only 2, or they are alternating (cust,item,cust,item) or any other way ?

HI Vikas, Use can use instream to import the data…

Thanks guys… it worked at last.