What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 35835 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > ADO.NET Interview Questions > What are the steps involved to fill a da ...

What are the steps involved to fill a dataset? Write the code for the same?

Interview question and answer by: Rajni.Shekhar | Posted on: 6/29/2012 | Category: ADO.NET Interview questions | Views: 704 | | Points: 40


Answer:

Steps to fill a dataset.

a. Create a connection object.
b. Create an adapter by passing the string query and the connection object as parameters.
c. Create a new object of dataset.
d. Call the Fill method of the adapter and pass the dataset object.

Example:
using System.Data;

using System.Data.SqlClient;

SqlConnection conn = new SqlConnection("server=localhost;Database=MyDB;userid=sa;pwd=sa");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


 Responses

Posted by: Itechsasi | Posted on: 29 Jun 2012 05:21:15 AM | Points: 10 | Alert Moderator 


When connection will open and close in dataAdapter. I heard that it is disconnected architecture.
if it is closed means while updating the dataset will open the connection again?.

Please explain about disconnected architecture.

Posted by: Rajni.Shekhar | Posted on: 29 Jun 2012 07:36:59 AM | Points: 10 | Alert Moderator 

You need to open a connection and close connection after finishing your work.
or use using (conn){
}
connection will be closed automatically after finishing using block.

>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Rajni.Shekhar

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 4:14:16 AM