.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

How to convert a Datareader into DataTable?

Posted By :Majith     Posted Date :September 08, 2010    Points :10   Category :.NET Framework 
Using the Execute() method of DataTable.

DataTable dt = new DataTable();
dt.Execute(dr);

You can also find related Interview Question to How to convert a Datareader into DataTable?  below: 

Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.

  
Prefix Notation:
^ - * +ABC - DE + FG

Postfix Notation:
AB + C * DE - - FG + ^ (More...)

Difference between Dataset and Datareader?

  
Data Set is a connectionless service and Data reader is a connection oriented service. Dataset is used to store the data, it contains collections of Datatable. Datareader is used to connect to the database for retrieving data.
Data Reader - Forward only where as Dataset - Can loop through dataset.
Data Reader - Connected Recordset where as DataSet - Disconnected Recordset
Data Reader - Less Memory Occupying where as DataSet - It occupies more memory
Data Reader - Only Single Table can be used where as Dataset - Datatable Concept allows data to be stored in multiple tables.
Data Reader - Read only where as DataSet - Can add/update/delete using the dataset
Data Reader - No relationship can be maintained where as DataSet - Relationship can be maintained.
Data Reader - No Xml Storage available where as DataSet - Can be stored as XML.
The Dataset is a core of disconnected architecture. Disconnected architecture means once you have retrieved the data from the database the data source is dropped. The disconnected data become very commonly. The dataset for the disconnected data from the Dataset object. The DataReader is a readonly, forward only stream from the database. While using the datareader can improve the application performance reduces the system overhead because only one buffer row at a time in memory.


Shashi Ray (More...)

How do I convert a numeric type to a string?

  
Call Sytem.Object.ToString(). For example, if the variable count is an integer, write the following:
string text = count.ToString(); (More...)

Difference between Int32.Parse,Convert.Int32

  
Int32.Parse Method:
-------------------
Converts the string representation of a number to its 32-bit signed integer equivalent.
-When s is a null reference, it will throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.

Convert.ToInt32(string):
-------------------------
Converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
-When s is a null reference, it will return 0 rather than throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.

Int32.TryParse Method:
----------------------
Converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.
-When s is a null reference, it will return 0.
-If s is other than an integer value, the out variable will have 0.
-When s represents a number out of range, the out variable will have 0. (More...)

How to add auto increment column in the DataTable?

  
To add auto increment column in the DataTable, we can set the AutoIncrement property of the DataColumn object as true and specify the seed value after adding that field into the DataTable object.
// create columns for the DataTable

DataTable dTable = new DataTable();

DataColumn auto = new DataColumn("AutoID", typeof(System.Int32));

dTable.Columns.Add(auto);

// specify it as auto increment field

auto.AutoIncrement = true;

auto.AutoIncrementSeed = 1;

auto.ReadOnly = true; (More...)

convert a value-type to a reference type is known as?

  
Boxing.

Boxing is the terminology used in .NET Framework to convert Value type to reference type (More...)

convert a Reference Type to a Value type is known as?

  
UnBoxing.

UnBoxing is the terminology used in .NET Framework to convert Reference Type to a Value type (More...)

How to deal with return value of stored procedure when you are using DataReader ?

  
To deal with such scenario, you can find "ParameterDirection.ReturnValue" in .net
You can use this parameter direction to read the return value of the stored procedure.

Following example can make it more clearer.
In case, you have following or similar type of return statement somewhere in your stored procedure.
Return -999
To read this value, following code works,

Dim result As Integer = 0
Dim retValParam As New SqlClient.SqlParameter("@RETURN_VALUE", SqlDbType.Int)
retValParam.Direction = ParameterDirection.ReturnValue
dbCommand.Parameters.Add(retValParam)
database.ExecuteNonQuery(dbCommand)
result = retValParam.Value ' here the result must contain the returned value. In this case, it will be -999 (More...)

What's the role of the DataReader class in ADO.NET connections?

  
a read-only dataset from the data source when the command is executed. (More...)

what is difference Between datareader and dataset ?

  
DataReader
===========
DataReader is like a forward only recordset. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them. DataReader will be the best choice where we need to show the data to the user which requires no transaction. As DataReader is forward only so we can't fetch data randomly. .NET Data Providers optimizes the datareader to handle huge amount of data.

Dataset
=======
DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas.
DataSet is always a bulky object that requires a lot of memory space compare to DataReader. We can say that the DataSet is a small database because it stores the schema and data in the application memory area. DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database. (More...)

Which function is used to convert the integer value into spaces?

  
The SPACE function convert the specified integer value into spaces.

SELECT SPACE(4)

It will output a string of four spaces " ". (More...)

What's the role of the DataReader class in ADO.NET connections?

  
It returns a read-only dataset from the data source when the command is executed. (More...)

Explain how to convert java file to jar files.

  
The following is the process:

- Type jar -cvf <.java file(s)>
where c stands for create, v stands for verbose and f indicates the file follows it, into which the archive to be stored. <.java file(s)> is the java files that are to be placed in the .jar file. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend