Data Adapters and Datasets (vb.net - VS2010)

Hello,

This is my 1st .net project and I'm using VB.net (vs2010).   Apologies if I'm using incorrect terminology.   Just trying to get going using the data objects.  

I've got a project started where I have set up a data source object (POSDataSet.xsd).    When I browse this object, I can see all of the table names and fields in the database.

In this project, I can see the following objects

POSDataSet  Object Type = Dataset
PurchaseOrder      Object Type = DataTable
PurchaseOrderTableAdapter = TableAdapter

Could someone provide a quick code sample of how I would use these objects to display the data in the Purchase Order Table?

Thanks in advance
keithflashAsked:
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.

FamousMortimerCommented:
You can display it in a datagridview like so

Datagridview1.DataSource = PurchaseOrder.Dataset.Tables(0).DefaultView
0
keithflashAuthor Commented:
What would you do prior to this command as far as instantiating objects and such?

Thanks
0
keithflashAuthor Commented:
I guess I'm having the most trouble understanding/using the data adapter object to fill the data table or data set.   Just from reading, it seems like this is what I need to do.    Am I off base on this?

The material I've read indicates that you need a connection object, a data adapter, and a data set.    I've really been having trouble communicating with these items and/or feeding them the correct arguments.

Thanks
0
FamousMortimerCommented:
You are correct.  Here is a small sample that should get you started

        Dim SQLcnstr As String = "Integrated Security=SSPI;" & _
                     "Initial Catalog=MyDatabaseName;" & _
                     "Data Source=SQLServerName\SQLServerInstance;"
        Dim dbConn As SqlConnection = New SqlConnection(SQLcnstr)
        dbConn.Open()
        Dim dbCmd As SqlCommand = New SqlCommand(sSQL, dbConn)
        Dim DA As SqlDataAdapter = New SqlDataAdapter(dbCmd)
        Dim DS As New DataSet = New DataSet
        DA.Fill(DS, "table")

Open in new window

I would recommend using the SQLHelper class which uses best practices and handles all of the objects for you.  Then you can create the dataset like below without all of the above code.

Dim ds As DataSet = SqlHelper.ExecuteDataset(MyConnstring, CommandType.Text, "Select * From YourTable")

Open in new window

SQLHelperClass.txt
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
Microsoft Development

From novice to tech pro — start learning today.