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

Hello,

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
<connectionStrings>
<add name="FBConnectionString" connectionString="Data Source=FORTISBLUE2008\SQLEXPRESS;Initial Catalog=YourLookup;User ID=blue;Password=blue;Connect Timeout=200" providerName="System.Data.SqlClient" /> --%>
</connectionStrings>

Current asp page:

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

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

x
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:
0

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:

1,1,4,2,"#",Description1
5,5,4,2,"#",Description2
3,3,6,3,"#",Description3
2,2,4,2,"#",Description4
4,5,4,2,"#",Description5

C# Code:

protected void readfile_Click(object sender, EventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Col1");
        table.Columns.Add("Col2");
        table.Columns.Add("Col3");
        table.Columns.Add("Col4");
        table.Columns.Add("Col5");
        table.Columns.Add("Col6");

        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;
        MyGridView.DataBind();
    }

Open in new window

0
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
ASP

From novice to tech pro — start learning today.