954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with sql reader

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 = <strong>new SqlDataReader</strong>();
existsRdr.<strong>Read</strong>();


Anyhelp would be great.
Thanks in advance.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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.
tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Oh, I see. Thanks for the help with that.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You