I want to refill a sql server table through a flat text file(CSV) in ASP.NET just giving the file name. Can somebody help me in this regard that i can do this.
Thanks & Best Regards
Hi saeednawaz,Check here for solution
http://bhatiaworld.blogspot.com/2005/06/transfering-data-from-text-filesource.html
But this solution is not taking ASP.net into consideration, but it will surely help u.|||
Hello,
Here is an example
' This example assumes the existence of a text file named myFile.txt ' that contains an undetermined number of rows with seven entries ' in each row. Creates a new DataSetDim myDataSet As New DataSet()' Creates a new DataTable and adds it to the Tables collectionDim aTable As New DataTable("Table 1")myDataSet.Tables.Add("Table 1")' Creates and names seven columns and adds them to Table 1Dim Counter As IntegerDim aColumn As DataColumnFor Counter = 0 to 6 aColumn = New DataColumn("Column " & Counter.ToString()) myDataSet.Tables("Table 1").Columns.Add(aColumn)Next' Creates the StreamReader to read the file and a string variable to' hold the output of the StreamReaderDim myReader As New System.IO.StreamReader("C:\myFile.txt")Dim mystring As String' Checks to see if the Reader has reached the end of the streamWhile myReader.Peek <> –1 ' Reads a line of data from the text file mystring = myReader.ReadLine ' Uses the String.Split method to create an array of strings that ' represents each entry in the line. That array is then added as a ' new DataRow to Table 1 myDataSet.Tables("Table 1").Rows.Add(mystring.Split(","c))End While
In the above example, new dataset will be created with one table that contains the
data of the myfile.txt
If you want to just fill a table then iterate throught myfile.txt, split values
and fill rows.
HTH
regards
No comments:
Post a Comment