Steps involved to fill a dataset, DOT NET Programming

What are the steps involved to fill a dataset ?

The sample code is shown below:

Private Sub LoadData()

Dim strConnectionString As String

strConnectionString = AppSettings.Item("ConnectionString") Dim objConn As New SqlConnection(strConnectionString) objConn.Open()

Dim objCommand As New SqlCommand("Select FirstName from

Employees")

objCommand.Connection = objConn

Dim objDataAdapter As New SqlDataAdapter() objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet

End Sub

In this type of questions interviewer is looking from the practical angle, that have you worked with dataset & datadapters. Let me try to explain the above code first and then we go to what steps must be told during the interview.

Dim objConn As New SqlConnection(strConnectionString)

objConn.Open()

The First step is to open the connection. Now again note the connection string is loaded from the config file.

Dim objCommand As New SqlCommand("Select FirstName from Employees") objCommand.Connection = objConn

The Second step is to create a command object with the appropriate SQL and set the connection object to this command

Dim objDataAdapter As New SqlDataAdapter()

objDataAdapter.SelectCommand = objCommand

The Third steps is to create an  Adapter object and pass the command object to the adapter object.

objDataAdapter.Fill(objDataSet)

The Fourth step is to load the dataset using the "Fill" method of the dataadapter.

lstData.DataSource = objDataSet.Tables(0).DefaultView

lstData.DisplayMember = "FirstName"

lstData.ValueMember = "FirstName"

The Fifth step is to bind to the loaded dataset with the GUI. At that moment the sample has a listbox as the UI. The Binding of the UI is completed by using the DefaultView of the dataset. Just to revise each dataset has tables and each table has views. In this sample we have only loaded one table that is Employees table so we are referring that with an index of zero.

Posted Date: 9/24/2012 2:46:32 AM | Location : United States







Related Discussions:- Steps involved to fill a dataset, Assignment Help, Ask Question on Steps involved to fill a dataset, Get Answer, Expert's Help, Steps involved to fill a dataset Discussions

Write discussion on Steps involved to fill a dataset
Your posts are moderated
Related Questions
Need code for Windows 8 and Windows Phone 8 that will http post images to a php file on web server. Project Description: I am working on two projects on both Windows 8/RT and

I need .NET Application Decompile Project Description: We have a minute .net utility which we want to decompile back into .net project. .Net application can be made availa

In what order do the events of an ASPX page execute. As a developer is it important to understand these events?   If you try to access it in Page_Load that is way previous than

Project Description: I require a C# Console project written to simply enter an Origin and Destination/Date on the United Airlines Site, from the returned page select and return

Define an event. Whenever an action takes place in a class, that class gives a notification to other classes or objects that are assigned to perform certain tasks. These notifi

They are triggered in the following order as shown below: Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveReque

Question: (a) How can you simple-bind controls at design mode? (b) How can a blank record be created in a dataset bound to the controls in a Windows form? (c) Datagrid

Encripter-Decripter application Project Description: I want an application which can encrypt - decrypt text, images, and music files as well as videos. Skills required are

What is DAR (Decision Analysis and Resolution)? The Decision Analysis and Resolution is to analyze possible decisions using a formal evaluation process that identifies alternat

What are the difference b/w System.String and System.StringBuilder classes? The System.StringBuilder can have mutable string where a variety of operations can be performed whil