Create datatable in memory
If I've to read records from a text file and then to create a datatable in memory and add records in it, then how i can set the datatype of each column. Formate of file 'll be like its first line will have name of columns for datatable.
Plzz tell me :(
[b]Question asked by visitor Sumaira[/b]
Re: Create datatable in memory
Hi Sumaira,
what type of data do You store in file,
are those the delimitered values (like using colon or tab)
or is it just plain text?
as for the datatypes, hmm,
it really depends what sort of data You have in those
columns
can You paste a sample of that data file?
It would be easier then to suggest some solutions ;)
Charles
I think i have the solution for your Problem
Hi :) i may be a little late to answer the question.
[B]Main Concept[/B] : Cover the text file in to an XML datafile.
[B]Assumptions Made [/B]: Your file contains | Name | some thing | Some thing |
[B]Solution elaborated[/B] :
First the file is a text file so reading from the file will not be a problem :)
Second the file is read and a equivalent XML file can be created
For Example :
Say a record is like this
[U][B]| Name | Age | Gender |[/B][/U]
[I]| Chibi | 20 | Male |[/I]
Then we can read the file with readLine() method and the break the data with the separators as the marker.
on breaking this create an XML record
<Student>
<name> Chibi </name>
<age> 20 </age>
<Gender> Male </Gender>
</Student>
[B][I]Please refer XML materials for further details in how to create the XML file correctly [/I][/B]
Then we can do things very easily.
Dataset.readXML("your XML file path goes here");
method can be used to get the Data directly in to the Dataset. Use the Update method to update all the changes from the Dataset to the Database.
:cool:
[B]I think that will do job.
If any doubt please thread.[/B]
:cool: