Data Adapters and Datasets (vb.net - VS2010)

Posted on 2013-10-01
Medium Priority
Last Modified: 2013-10-02

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
Question by:keithflash
  • 2
  • 2
LVL 10

Expert Comment

ID: 39537194
You can display it in a datagridview like so

Datagridview1.DataSource = PurchaseOrder.Dataset.Tables(0).DefaultView

Author Comment

ID: 39538227
What would you do prior to this command as far as instantiating objects and such?


Author Comment

ID: 39538246
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.

LVL 10

Accepted Solution

FamousMortimer earned 2000 total points
ID: 39539516
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)
        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


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question