0

Ok, I am trying to read data back from a database, when I build my program it throws an error saying: "No overload for method 'SqlDataReader' takes '0' arguments."

Here is the code from the program:

SqlDataReader existsRdr = [b]new SqlDataReader[/b]();
existsRdr.[b]Read[/b]();

Anyhelp would be great.
Thanks in advance.

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Dark_Omen
0

You return a SqlDataReader as the result of the .ExecuteReader() method of the Command object:

SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
 myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(myReader.Read()) 
{
    Console.WriteLine(myReader.GetString(0));
}
myReader.Close();
//Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.