How do I pull data in from a database table rather than an xml file in c#?

I presently have a ListView data control (Visual Studio 2008 .NET 3.5) connected to an object data source that is pulling data via an xml file. Is it possible to connect to an sql database table instead of the xml file?
public CustomersDataObject()
    {
        this._Customers = HttpContext.Current.Session["Customers"] as DataSet;
 
        if (this._Customers == null)
        {
            this._Customers = new DataSet();
            
            this._Customers.ReadXml(HttpContext.Current.Server.MapPath(@"App_Data\customers.xml"));
 
            HttpContext.Current.Session["Customers"] = this._Customers;
        }
    }

Open in new window

ShepweddAsked:
Who is Participating?
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.

Bob LearnedCommented:
You could replace the ObjectDataSource with an SqlDataSource, and I would think that the switch would be pretty seamless.

Bob
0
ShepweddAuthor Commented:
Unfortunately I need to use the ObjectDataSource as I am using a DataObject behind file to run other events.

Basically I am trying to mirror the below table design which uses the ajax auto complete extender to filter data...

http://mattberseth.com/blog/2007/12/creating_a_google_suggest_styl.html

I am wanting the above to work with my sql database table instead of the xml file if possible?...

0
Bob LearnedCommented:
You are using a DataSet to read from an XML file.  You could use an SqlDataAdapter to fill the DataSet from SQL Server instead.

Bob
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

ShepweddAuthor Commented:
For more information - I have managed to link the listview (found at the above url) with the Linq data source (allowing me to enable easy insert, edit and delete commands) but through the Linq data source I'm not sure how to filter the listview by using the ajax auto complete text box and drop down....urrrggghhh!! Any help will be much appreciated!
0
ShepweddAuthor Commented:
I'm actually hoping to implement the Linq data source approach rather than the Object Data Source approach, but thanks for the data adapter idea. Any thoughts on how I might connect a auto complete text box to the linq data source in order to filter the data for a user?
0
ShepweddAuthor Commented:
How would I use an SqlDataAdapter to fill the DataSet from SQL Server, example code...?

Thanks.
0
Bob LearnedCommented:
Example:


public static DataTable GetUserData(int userID)
{
 string connectionString = ConfigurationManager.ConnectionString["MyConnection"].ConnectionString;
 
 using (SqlDataAdapter adapter = new SqlDataAdapter("spGetUser", connectionString)
 {
   adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
   adapter.SelectCommand.Parameters.AddWithValue("@UserID", userID);
   DataTable dt = new DataTable();
   adapter.Fill(dt);
   return dt;
 }
}

Open in new window

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
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
.NET Programming

From novice to tech pro — start learning today.