Problem with sql reader

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Problem with sql reader

 
0
  #1
May 26th, 2005
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 = new SqlDataReader();
existsRdr.Read();

Anyhelp would be great.
Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Problem with sql reader

 
0
  #2
May 27th, 2005
You return a SqlDataReader as the result of the .ExecuteReader() method of the Command object:

  1. SqlConnection myConnection = new SqlConnection(myConnectionString);
  2. SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
  3. myConnection.Open();
  4. SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
  5. while(myReader.Read())
  6. {
  7. Console.WriteLine(myReader.GetString(0));
  8. }
  9. myReader.Close();
  10. //Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Problem with sql reader

 
0
  #3
May 28th, 2005
Oh, I see. Thanks for the help with that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC