Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Read txt File to a DataSet

Reply
Thread Tools

Read txt File to a DataSet

 
 
ruca
Guest
Posts: n/a
 
      02-26-2004
Hi,

Can I read a .TXT File to a DataSet? How can I do that?
I want to read his lines to a DropDownList. This lines are the names of
employees that I export from an application that I have.
I export them to a .txt file and I want to "work" with this employees in my
aspx page. Can you help me?
It's a little bit strange, but it's what I need.


--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca


 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      02-26-2004
Can you possibly change the textfile to xml? The data set can suck this up
pretty easily because it has built in support for this. Otherwise, you will
need to parse the contents of the file and create new rows adding the
contents to these rows. It's not going to be pretty this way but these are
the options that you have.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"ruca" <> wrote in message
news:eFD8r%23H$...
> Hi,
>
> Can I read a .TXT File to a DataSet? How can I do that?
> I want to read his lines to a DropDownList. This lines are the names of
> employees that I export from an application that I have.
> I export them to a .txt file and I want to "work" with this employees in

my
> aspx page. Can you help me?
> It's a little bit strange, but it's what I need.
>
>
> --
>
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
>



 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      02-26-2004
> Can I read a .TXT File to a DataSet? How can I do that?

You could programmatically pick through the text file and add it to the
DataSet, yes. But there's not a method in the DataSet class like,
ReadTextFile().

> I want to read his lines to a DropDownList.


Perhaps an easier approach would be to just programmatically step through
the lines of code and add it to the DropDownList's Items collection.
Something like:

StreamReader sr = File.OpenText(filepath);
while (sr.Peek() >= 0)
myDDL.Items.Add(new ListItem(sr.ReadLine());
sr.Close();


Something like that ought to do the trick.

Happy Programming!

--

Scott Mitchell

http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!




 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      02-26-2004
Hi Ruca,

Without the FMT=Delimited\ it is a row with vbcrlf

I hope this helps?

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
///


 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      02-26-2004
On Thu, 26 Feb 2004 15:49:47 -0000, "ruca" <> wrote:

¤ Hi,
¤
¤ Can I read a .TXT File to a DataSet? How can I do that?
¤ I want to read his lines to a DropDownList. This lines are the names of
¤ employees that I export from an application that I have.
¤ I export them to a .txt file and I want to "work" with this employees in my
¤ aspx page. Can you help me?
¤ It's a little bit strange, but it's what I need.

Could you post a couple of lines from your text file so we can see the format?


Paul ~~~
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
ruca
Guest
Posts: n/a
 
      02-27-2004
It's quite easy:

Name, Code, Password
Name, Code, Password
Name, Code, Password
Name, Code, Password
Name, Code, Password
Name, Code, Password


ruca


"Paul Clement" <> escreveu na
mensagem news:...
> On Thu, 26 Feb 2004 15:49:47 -0000, "ruca" <> wrote:
>
> ¤ Hi,
> ¤
> ¤ Can I read a .TXT File to a DataSet? How can I do that?
> ¤ I want to read his lines to a DropDownList. This lines are the names of
> ¤ employees that I export from an application that I have.
> ¤ I export them to a .txt file and I want to "work" with this employees in

my
> ¤ aspx page. Can you help me?
> ¤ It's a little bit strange, but it's what I need.
>
> Could you post a couple of lines from your text file so we can see the

format?
>
>
> Paul ~~~
> Microsoft MVP (Visual Basic)



 
Reply With Quote
 
ruca
Guest
Posts: n/a
 
      02-27-2004
And What I want to appear in my dropdownlist it's only the Name



"ruca" <> escreveu na mensagem
news:Oz9W4dR$...
> It's quite easy:
>
> Name, Code, Password
> Name, Code, Password
> Name, Code, Password
> Name, Code, Password
> Name, Code, Password
> Name, Code, Password
>
>
> ruca
>
>
> "Paul Clement" <> escreveu na
> mensagem news:...
> > On Thu, 26 Feb 2004 15:49:47 -0000, "ruca" <> wrote:
> >
> > ¤ Hi,
> > ¤
> > ¤ Can I read a .TXT File to a DataSet? How can I do that?
> > ¤ I want to read his lines to a DropDownList. This lines are the names

of
> > ¤ employees that I export from an application that I have.
> > ¤ I export them to a .txt file and I want to "work" with this employees

in
> my
> > ¤ aspx page. Can you help me?
> > ¤ It's a little bit strange, but it's what I need.
> >
> > Could you post a couple of lines from your text file so we can see the

> format?
> >
> >
> > Paul ~~~
> > Microsoft MVP (Visual Basic)

>
>



 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      02-27-2004
On Fri, 27 Feb 2004 09:56:23 -0000, "ruca" <> wrote:

¤ It's quite easy:
¤
¤ Name, Code, Password
¤ Name, Code, Password
¤ Name, Code, Password
¤ Name, Code, Password
¤ Name, Code, Password
¤ Name, Code, Password
¤

Here is how you would get it into a DataSet:

Dim TextConnectionString As String
TextConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "c:\TestData" & ";" & _
"Extended Properties=""Text;HDR=NO;"""
Dim TextConn As New System.Data.OleDb.OleDbConnection(TextConnectionSt ring)
TextConn.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from test.csv", TextConn)

Dim ds As DataSet = New DataSet("CSVFiles")
da.Fill(ds, "TestFile")

'...
'...
'...

TextConn.Close()


Paul ~~~
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      02-27-2004
it's going to be messy, i'd rather just read the strings from the file and
add them to the dropdown

//setup a loop here

Dropdownlist.items.add(new listitem(passwordtext,passwordtext));



if you insist on using a dataset it would go something like this

DataSet dsTemp = new DataSet();

DataTable Tables = new DataTable();

dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add("PassWord", System.Type.GetType(
"System.String" ) );

DataRow myRow = dsTemp.Tables[0].NewRow();

myRow[0] = "password read from file";

dsTemp.Tables[0].Rows.Add(myRow);

dropdownlist.datatext = "PassWord";
dropdownlist.datasource = dsTemp;
dropdownlist.databind();

you can see that this is really messy code.
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"ruca" <> wrote in message
news:uvEWuiS$...
> And What I want to appear in my dropdownlist it's only the Name
>
>
>
> "ruca" <> escreveu na mensagem
> news:Oz9W4dR$...
> > It's quite easy:
> >
> > Name, Code, Password
> > Name, Code, Password
> > Name, Code, Password
> > Name, Code, Password
> > Name, Code, Password
> > Name, Code, Password
> >
> >
> > ruca
> >
> >
> > "Paul Clement" <> escreveu na
> > mensagem news:...
> > > On Thu, 26 Feb 2004 15:49:47 -0000, "ruca" <> wrote:
> > >
> > > ¤ Hi,
> > > ¤
> > > ¤ Can I read a .TXT File to a DataSet? How can I do that?
> > > ¤ I want to read his lines to a DropDownList. This lines are the names

> of
> > > ¤ employees that I export from an application that I have.
> > > ¤ I export them to a .txt file and I want to "work" with this

employees
> in
> > my
> > > ¤ aspx page. Can you help me?
> > > ¤ It's a little bit strange, but it's what I need.
> > >
> > > Could you post a couple of lines from your text file so we can see the

> > format?
> > >
> > >
> > > Paul ~~~
> > > Microsoft MVP (Visual Basic)

> >
> >

>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      02-27-2004
Hi Alvin,

I can asure you that my sample is working.
(There was originaly a datagrid in it, which could be now a combobox at the
end)

But that is so basic.

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting how often the same word appears in a txt file...But my codeonly prints the last line entry in the txt file dgcosgrave@gmail.com Python 8 12-19-2012 06:29 PM
Diff. between FileWriter("f.txt") and OutputStreamWriter(new FileOutputStream("f.txt")) ? Jochen Brenzlinger Java 7 09-15-2011 01:23 AM
Read .txt file like .py file King Python 2 07-28-2008 09:39 AM
Opening a txt file to view ( i.e. readme.txt) Sameen C++ 2 08-29-2005 03:14 PM
Read txt File to a DataSet ruca ASP .Net 15 02-27-2004 08:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57