Last post May 29, 2010 03:23 PM by lioespina
May 28, 2010 09:53 PM|LioEspina|LINK
I have a text file coming from another system that is in fixed format with header and details information regarding a request of material, looks like:
HDR 1000 HeaderDescription
DTL ProductId Productdescription qty ...........
I can read the file using streamreader on a "continous way" inside a do while loop, and parse it to obtain th different fileds required.
i want to read the file, identify header line and fill a datatable, then identify details lines and fill another datatable to be able to insert both tables on the same transaction scope, if something fails rollback the insert.
Im using a access 2003 database as backend and custom DAL and Business objects.
Thanks in advance for your help.
Insert into Access Database return primary key
ADO Dataset DataReader
May 29, 2010 12:07 AM|PNasser|LINK
Is the custom DAL from some software you can link to? or home grown code? the DAL will have to allow for transactions, I'm not sure how you could wrap your custom DAL in some other transaction framework (if your DAL doesn't support transactions).
You'll have to look at your own DAL code to determine if transactions are supported. Alternatively, you could use ADO.net for just this bulk insert, and keep your DAL for the rest, check out:
http://www.15seconds.com/issue/040914.htm. It's a good primer and gives you some good examples of how you could impliment your transaction code
May 29, 2010 03:23 PM|LioEspina|LINK
Thanks for your reply, i´m using ADO.NET oledb datatables and datareaders , i know i can use oledbtransaction inside the same connection using statement to commit in the same transaction scope(or rollback on fail), what i can really figure out its how to
identify and make the datatables from the streamreader so it fills both datatables and then perform the insert inside that oledbtransaction.
I guess it would be like:
1.- Read line
2.- identify if header or detail
3.- fill header datatable
4.- loop until next header line its found and fill details datatable
5.- use oledbcommand to insert the header datatable(with just one row), returning the header id.
6.- loop through details rows in details datatable and insert it using returned id for the foreing key.
7.- Repeat the process until end of streamreader.
i just cant figure out how to code it in the right way.
Thanks again for the reply,