Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi all, pls i need your help, i am trying to execute a query and put all the retrieved data in a data set, but i get this error " cannot implicitly convert type 'int' to 'system.data.dataset'".
Here's the code
C#
String Astra_conn = ConfigurationManager.ConnectionStrings["AstraSeverConnection"].ConnectionString;

System.Text.StringBuilder sql = new System.Text.StringBuilder();

this is a small piece of the sql
C#
sql.Append(" SELECT ROWNUM AS ID, institution, LPAD (a.zone_name, 3, '0') AS campus, ");
sql.Append(" term_name AS term, student_instance_id AS student_id, subject, course, ");
sql.Append(" section_name AS section_num, offering AS title, ");

Its OracleConnection because it is an Oracle server otherwise, it would be SqlConnection.
C#
DataSet rs = new DataSet();
   OracleConnection Astra_db_Conn = new OracleConnection(Astra_conn);
   string myquery = sql.ToString();
   OracleCommand cmd = new OracleCommand(myquery);

   Astra_db_Conn.Open();
   try
   {
       SqlDataAdapter adpt = new SqlDataAdapter();
       rs = cmd.ExecuteNonQuery(); // this is where is get the error.
       adpt.Fill(rs);

   }
   catch(Exception e)
   {
  log.Error("*** ERROR *** IRISExportQueries.loadStudentInfoLearningSites():" + e);

   }

I have also tried
Astra_db_Conn.Open();
C#
 try
 {
     SqlDataReader reader = new SqlDataAdapter();
     reader = cmd.ExecuteNonQuery(); // this is where is get the error.
 

 }
 catch(Exception e)
 {
log.Error(&quot;*** ERROR *** IRISExportQueries.loadStudentInfoLearningSites():&quot; + e);</pre>

 }

But then i get the error: "cannot implicitly convert type 'int' to 'System.Data.SqlClient.SqlDataReader'".

Thanks your help will be very much appreciated.
Posted
Updated 14-Aug-13 20:39pm
v2

1 solution

ExecuteNonQuery returns an integer of the number of rows/records affected by the operation. Instead of using ExecuteNonQuery you need to use ExecuteReader.

ExecuteNonQuery -> Used for Updates, Inserts and Deletes mostly.
ExecuteReader -> Returns a data reader that can load records, for Select statements.
ExecuteScalar -> Returns the first column of the first record returned by the query. Useful for counting, averaging, etc.
 
Share this answer
 
Comments
rudolph098 14-Aug-13 21:58pm    
Thanks that solved on problem, but there is a new one.

Since its an oracleDb, i decided to change all the classes since there was the Oracle version for all the Sql.

To clarify: Dataset data1 = new Dataset(), so the oracle version of this is OracleDataset data1 = new Dataset(). So for all the other like SqlDataReader, SqlDataAdapter etc. all i did was to add Oracle in front of it for the purpose of uniformity and so the V.S stops complaining about conversion between the classes.

but the real question is that i am getting a new error message, after i made this change

OracleConnection Astra_db_Conn = new OracleConnection(Astra_conn);
string myquery = sql.ToString();
OracleCommand cmd = new OracleCommand(myquery);

Astra_db_Conn.Open();
try
{
OracleDataAdapter adpt = new OracleDataAdapter();
rs=cmd.ExecuteReader(); // this is where i get the error
adpt.Fill(rs);

} catch(Exception e)
{
log.Error(&quot;*** ERROR *** IRISExportQueries.loadStudentInfoLearningSites():&quot; + e);

}

// but then i get the error: "cannot implicitly convert type 'Data.Oracle.OracleDataReader' to 'Data.Oracle.OracleDataSet'"

// thanks for the help
Ron Beyer 14-Aug-13 22:02pm    
Please see StackOverflow answer for an example on how to fill an Oracle dataset.
rudolph098 14-Aug-13 23:07pm    
thank you.
Ron Beyer 15-Aug-13 0:02am    
Please mark this as Answer if this solved your problems so people in the future can find it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900