Can you use a text file as a data source for a GridView in ASP


I have a working ASP page that is pulling data from a SQL table into a Gridview with a select statement.  I would like to do the same thing using a text file vs the SQL table as my data source.  Is this possible to create a system DSN and connect to the text file to pull my data? If not can you point me into the right direction?

Current Web.cofig
<add name="FBConnectionString" connectionString="Data Source=FORTISBLUE2008\SQLEXPRESS;Initial Catalog=YourLookup;User ID=blue;Password=blue;Connect Timeout=200" providerName="System.Data.SqlClient" /> --%>

Current asp page:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FBConnectionString %>" SelectCommand="SELECT * FROM dbo.APInvoice WHERE VendorName LIKE @VName">
        <asp:ControlParameter ControlID="tbVName" Name="VName" PropertyName="Text" />
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontyWeb Ninja at largeCommented:
here's a more detailed answer on parsing out a text file and filling up a GridView:

Text File Contents:


C# Code:

protected void readfile_Click(object sender, EventArgs e)
        DataTable table = new DataTable();

        using (StreamReader sr = new StreamReader(@"c:\pathToFile\file.txt"))
            while (!sr.EndOfStream)
                string[] parts = sr.ReadLine().Split(',');
                table.Rows.Add(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]);
        MyGridView.DataSource = table;

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.