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
0
Comments
If that is the case, I would do the following:
Declare 7 Variables in your Dataport:
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;
i have to insert records simaltanously into two tables. 1st line into customer table and 2nd line into item table.
can u tell me how??
because i am a fresher....
What do you mean with simultaniously? You can only read one line of the file per step! And with the counter you decide if you have to insert a customer or a item.
Greetings,
Frank
but it is not entering into the first loop itself.
Tommy
In the PreDataItem code, you must enter another line of code...
gvImportCounter := 1;
This will ensure that the first section of code is executed...
Without this line of code, the Dataport will start to run without a value in the gvImportCounter variable - thus not executing the first section of code.