Why sql Data Reader object not created
Answers were Sorted based on User's Feedback
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 |
Answer / alex dorfman
The type 'System.Data.SqlClient.SqlDataReader' has no
constructors defined
Is This Answer Correct ? | 11 Yes | 5 No |
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 |
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 |
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 |
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 |
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 |
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 |
What is linq and entity framework?
What is a serialized object?
Explain the two fundamental objects in ado.net?
What is the executescalar method?
What are the different row versions available?
How to creating a SqlCommand Object?
About ADO and its objects ?
How can you add or remove rows from the datatable object of dataset?
If we want to connect to many databases in dataaccess layer such as MSAccess,Sql server,oracle means not to a particular database depends on condition we have to connect to appropriate database in this scenario if we without changing code Ho wdo you handle this situation?
can we change the data in dataset? if yes what is the process?
How to check if a datareader is closed or opened?
What are the three Ado objects?
6 Answers Microsoft, StarSoft,