Link to home
Start Free TrialLog in
Avatar of XGIS
XGISFlag for Australia

asked on

Generate EDI from data in sql via asp.net c#

Hello Experts,

I am faced with a task where i need to generate EDI message for a shipping booking page in a clients asp.net application all the relevant in formation is captured in ms sql 2008 but I am un sure of the code behind to acheive this... any help with code would be most appreciated..

p.s the schema for the EDI message has not yet been decided as we are waiting to the shipping control company to get back to us with a schema.
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Well, an EDI document is essentially flat file. Theres not going to be a whole lot you can do without knowing the schema, other than preping the data retrieval mechanisms.

Which bit specifically are you unsure about?
Avatar of XGIS

ASKER

All of it! understand that the schema is critical but kust imagine that I need to generate an EDI with customerName, Company, Address and country how would I acheive this
It partly depends on what you want to do with the result. Are you creating a file to store on disc, or will you be transmitting the data directly to a recipient, or something else?

Either way the basic process would be:

1) Retrieve the data from the datastore (either as a DataTable, DataReader, Xml, or custom business object collection)
2) Create an output stream (FileStream, MemoryStream; depending on what you need to do with the output)
3) Iterate over your data and write to the output stream.
4) Save the stream to disc/transmit to another process.
Avatar of XGIS

ASKER

basically the form will be open, the user will enter data in to lets just say a series of text boxes when they click submit the data in the textboxes will write to datatable then to EDI then to sql, or SQL then in the onclick also write EDI from sql or something like this..... but I don't know if writing EDI is the same as xml with different extention or if it is completely different so therefore I have no idea on how to code the generation.
Avatar of XGIS

ASKER

oh sounds possible it will be transmitted... so your saying when the user adds data to the textboxes I should save the values in the textboxes to a dataTable then write the content of the dataTable to both SQL and EDI then transmit the EDI?

to loop through the dataTable would you recomend that i use a foreach loop?
Personally I would create a class that represents the data you are capturing. When the user "submits" the data you populate an instance of the class from your textboxes.

You can then have the class populate a database and/or produce EDI as necessary. EDI files are essentially flat files that use fixed width fields for their values. Each line in the EDI file is marked with a control code that denotes what type of data the line contains (all of this should be explained in the schema when you get hold of it). It's more akin to a fixed-width CSV file than XML.
Avatar of XGIS

ASKER

ok I Think I understand.... would you by chance have a sample of such a class???
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XGIS

ASKER

Thankyou so much.... I am still waiting for the schema, but if I accept and give you the points now will you still be able to answer any questions when I get the schema????
Avatar of XGIS

ASKER

p.s these points will push you up to pos 23 sweet.... :-)
I'll be around intermittently....I do have a day job as well :o)

But if i'm not here then i'm sure one of the other experts will be on hand.