Results 1 to 4 of 4

Thread: Cannot Convert Type

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Cannot Convert Type

    Error Message:
    DatabaseClass.cs(102,12): error CS0029: Cannot implicitly convert type 'System.Data.DataSet' to 'System.Data.SqlClient.SqlDataReader'
    Code:
    public DataSet db_query(string SqlStatement, bool isStoredProc)
    	{
    		DataSet dSet = new DataSet();
    
    		try
    		{
    			if(SqlStatement == "")
    			{
    				MessageBox.Show("SQL Statment is empty.");
    			}
    			
    			if(isStoredProc == true)
    			{
    				String strQuery = "EXEC " + SqlStatement.Trim();
    				SqlDataAdapter sAdapter = new SqlDataAdapter(strQuery,myConnection);
    				sAdapter.Fill(dSet,SqlStatement);
    			}
    			else
    			{
    				string strQuery = SqlStatement.Trim();
    				SqlDataAdapter sAdapter = new SqlDataAdapter(strQuery,myConnection);
    				sAdapter.Fill(dSet,SqlStatement);
    			}
    		}
    		catch(Exception exp)
    		{
    			MessageBox.Show("Error fetching records for the query:- " + SqlStatement + ". Possible cause:- " + exp.ToString() );
    		}	
    				
    		return(dSet);
    	}
    
    public static void Main()
    	{
    		string myConnectionString = ("server=localhost;database=pubs;user id=steve;password=jensen;");
    		Database myDB = new Database();
    		SqlDataReader reader;
    		
    		
    		db_open(myConnectionString); 
    		reader = myDB.db_query("SELECT * FROM authors", false);
    		
    		while(reader.Read()) 
    	   {
    		  Console.WriteLine(reader["au_lname"]);
    	   }
    		
    		db_close();
    	}
    Obviously the issue is in reader = myDB.db_query, since db_query returns a DataSet and I am trying to read the returned DataSet with the SqlReader...Any ideas on how to do this???
    Last edited by Memnoch1207; Sep 30th, 2003 at 12:19 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width