Why sql Data Reader object not created

Answers were Sorted based on User's Feedback



Why sql Data Reader object not created..

Answer / manish t

the command in the above code uses cmd.executereader ()
which means an datareader object is returned as a result of
the execution .....which essentially means one datar reader
object getting assigned to another datareader object

dr = cmd.executereader

so it is simply assigning of objects and does not require
new keyword as the datareader inside the execute reader has
already allocated space and it is just assigning it to a
different object ...this is true with executedataset as
well ...remember the rule is that corret type should be
returned. it is same in case of any objects ..try creating
an object A with new keyword and another object B of same
type without new key word ...and then assign the A to B and
you will find that By ref all properties are avialable to b

Is This Answer Correct ?    7 Yes 0 No

Why sql Data Reader object not created..

Answer / alex dorfman

The type 'System.Data.SqlClient.SqlDataReader' has no
constructors defined

Is This Answer Correct ?    11 Yes 5 No

Why sql Data Reader object not created..

Answer / boopathiraj

we can't create an object for data reader because the
datareader is used to retrive the data's from the database
and it uses only some small amount of databases unlike
dataset.We can just create the variable for the datareader
is possible.And then THE CONSTRUCTORS WAS NOT DEFINED BY
SYSTEM.DATA.SQLCLIENT.SQLDATAREADER.(i.e)when you typed
(System.data.sqlclient)upto this is possible if you use
(System.data.sqlclient)(.sqldatareader)--->Not possible and
it is applicable when you use microsoft visual studio.net

Is This Answer Correct ?    8 Yes 4 No

Why sql Data Reader object not created..

Answer / tahir

The DataReader object is the ADO.NET counterpart of the read-only, forward-only default ADO cursor. The DataSet is a container that can be programmatically filled with static snapshot of data. In this sense, it can be seen as a repository of disconnected recordsets. There's no Recordset component in the ADO.NET object model, but the DataTable object is the .NET double of a disconnected recordset.

Is This Answer Correct ?    2 Yes 1 No

Why sql Data Reader object not created..

Answer / kalirajan

SqlConnection con = new SqlConnection("");
con.Open();
SqlCommand cmd = new SqlCommand("", con);

SqlDataReader dr;

dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr[0].ToString();


}

dr.Close();


Try this code...

Is This Answer Correct ?    8 Yes 8 No

Why sql Data Reader object not created..

Answer / tahir

The DataReader object is the ADO.NET counterpart of the read-only, forward-only default ADO cursor. The DataSet is a container that can be programmatically filled with static snapshot of data. In this sense, it can be seen as a repository of disconnected recordsets. There's no Recordset component in the ADO.NET object model, but the DataTable object is the .NET double of a disconnected recordset.

Is This Answer Correct ?    2 Yes 2 No

Why sql Data Reader object not created..

Answer / shakeer

We don't require to create object of DataReader class.

Because , For Example

if any string value is there like "Hello"
we will capture that value into String Class varible.

String s = "Hello";

In the same way when we call ExecuteReader() method, the
return type is DataReader


METHOD RETURN TYPE
ExecuteReader() ----> Datareader

DataReader: Which is having the capacity of holding the data
in the form of Rows and Columns

when we need to capture the value of string type, we
created the variable of the String class & captured it.
Similarly in the case of Datareader, we will create variable
of Datareader and capture the return type of ExecuteReader()
method.


So, DataReader dr = cmd.ExecuteReader();

Is This Answer Correct ?    0 Yes 0 No

Why sql Data Reader object not created..

Answer / manish

after some investigation i have found that because the
sqldatareader has no constructor defined in it an object
cannot be created.

Is This Answer Correct ?    2 Yes 4 No

Why sql Data Reader object not created..

Answer / deep

because it ia an abstract class

Is This Answer Correct ?    7 Yes 13 No

Post New Answer

More ADO.NET Interview Questions

Explain advantages of ado.net?

0 Answers  


What is reference by value how does it works in .net?

2 Answers   SQL Star,


what are the two key events for the sql connection class? explain the differnce between the two.

2 Answers   HCL, NIIT, Zensar,


What is data relation in ado.net?

0 Answers  


What are the key events of sqlconnection class?

0 Answers  






What are the different ado.net namespaces?

0 Answers  


What is command class in ado.net?

0 Answers  


What is ado control?

0 Answers  


How To Update A Column In A DataGrid Using C#.NET? I am getting InvalidCastException as (Specified cast is not valid) while updating 2nd column in a datagrid? Id,firstname,lastname are the three columns of my datagrid respectively. I wanted to edit the second column(lastname) and update it. I did the following code in DataGrid's updatecommand(),but failed to update ! Int varid=(int)DataGrid1.DataKeys[e.Item.ItemIndex]; TextBox lnm=(TextBox)e.Item.Cells[2].Controls[0]; string str=lnm.Text ; SqlCommand cmd=new SqlCommand("update customer set lastname='" + str + "' where id=" + varid + "",con); cmd.ExecuteNonQuery(); DataGrid1.EditItemIndex=- 1; DataGrid1.DataBind();

2 Answers   Mind Tree, TCS,


What are the uses of Stored Procedure?

0 Answers  


Explain different methods and Properties of DataReader which you have used in your project?

2 Answers  


What are the Features of a dataset

0 Answers   BirlaSoft,


Categories