Reads the specified columns in a text file and the columns in the text file.
I saw a problem on the forum today. This is probably the case. I read the specified columns in the text file and store them in the database.
Insus. NET takes less time to read text.
Create a text file and add several lines of text. Each row has several columns separated by commas.
adf,adfadf,adsfgads,qwer,wrt,wrey,asdfs,qwer,tryerqert6uy7,468u4,578,qewrqew,qwertwet,67u46,45676,45qer87,47857,et356y,etyedghadsadf,adfadf,adsfgads,qwer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,5ZXC78,qewrqew,qwertrtwet,67u46,456qer76,4wu1587,47wr857,etyty,etyedghadwrf,adfadf,adsfgads,qwuier,wrqert,wrey,aswrtdfs,qwer,try790ert6uy7,468u4,572458,qewrqew,qwertwet,67u46,45676,4rwt587,47857,etuoipy,etyedghad356f,adf1324adf,adsfgads,qwasdfer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,5rt78,qewrqew,qwertwetyet,67u46,45676,4zcxv587,47857,ety,etyedghadf356,adfadf,adsfga34ds,qwer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,578,qewwtrrqew,qwerqertwet,67u4ety6,45676,4587,47857,etwey,etyedghad869f,adfeadf,adsfqrgads,qwer,wrt,wrey,as689dfs,qwer,trytyert6uy7,468u4,578,qewrqew,qweroyiotwet,67u46,45676,4535687,47857,ety,etyedgh
If you want to use this example for demonstration, you can save it as a. txt file.
Next, we can implement this. No matter whether a text file has a column name, you are not concerned about the column name of the data table.
Write a model as a data table, for example:
In this category, you can see an interpreted function: TryParase (); it processes text data rows. Read the first 10 columns of each text file. Of course, you can change the number of columns to be read.
Also, check whether there are blank lines and spaces at the beginning and end of each line of text. Whether the number of columns is sufficient and whether there are other rule separator characters.
Then you can use this number and function in the program:
In the code, Insus. NET displays the obtained data in the GridView control, omitting the function of storing data in the database.
Finally, the result is displayed: