Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can we use dataadapter to fill a dataset ?
What are the steps involved to fill a dataset ?
✍: Guest
Sample code is provided in “WindowsDataSetSample” folder in CD.”LoadData” has all the implementation of connecting and loading to dataset. This dataset is finally bind to a ListBox. Below is the sample code.
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 such type of questions interviewer is looking from practical angle, that have you worked with dataset and datadapters. Let me try to explain the above code first and then we move to what steps should be told during interview.
Dim objConn As New SqlConnection(strConnectionString) objConn.Open()
First step is to open the connection.Again note the connection string is loaded from config file.
Dim objCommand As New SqlCommand(“Select FirstName from Employees”) objCommand.Connection = objConn
Second step is to create a command object with appropriate SQL and set the connection object to this command.
Dim objDataAdapter As New SqlDataAdapter() objDataAdapter.SelectCommand = objCommand
Third steps is to create the Adapter object and pass the command object to the adapter object.
objDataAdapter.Fill(objDataSet)
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”
listbox as the UI. Binding of the UI is done by using DefaultView of the dataset. Just to revise every dataset has tables and every table has views. In this sample we have only loaded one table i.e. Employees table so we are referring that with an index of zero.
2007-10-24, 5090👍, 0💬
Popular Posts:
How To Use mysqlbinlog to View Binary Logs? - MySQL FAQs - Server Daemon mysqld Administration If yo...
What is the purpose of Replication ? Replication is way of keeping data synchronized in multiple dat...
Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?...
How To Compile a JUnit Test Class? Compiling a JUnit test class is like compiling any other Java cla...
What is difference between SITP and UTP in testing ? UTP (Unit Test Plan) are done at smallest unit ...