不能隐式地将类型'int'转换为'system.data.dataset' [英] cannot implicitly convert type 'int' to 'system.data.dataset'
问题描述
大家好,我需要你的帮助,我正在尝试执行查询并将所有检索到的数据放入数据集中,但我得到此错误无法将类型'int'隐式转换为'system.data.dataset '。
这是代码
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
String Astra_conn = ConfigurationManager.ConnectionStrings["AstraSeverConnection"].ConnectionString;
System.Text.StringBuilder sql = new System.Text.StringBuilder();
这是一小段sql
this is a small piece of the sql
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, ");
它的OracleConnection因为它是Oracle服务器,否则就是SqlConnection。
Its OracleConnection because it is an Oracle server otherwise, it would be SqlConnection.
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);
}
我也试过
Astra_db_Conn.Open();
I have also tried
Astra_db_Conn.Open();
try
{
SqlDataReader reader = new SqlDataAdapter();
reader = cmd.ExecuteNonQuery(); // this is where is get the error.
}
catch(Exception e)
{
log.Error("*** ERROR *** IRISExportQueries.loadStudentInfoLearningSites():" + e);</pre>
}
然后我得到错误:无法隐式转换类型'int'
到'System.Data.SqlClient.SqlDataReader'
。
非常感谢您的帮助。
But then i get the error: "cannot implicitly convert type 'int'
to 'System.Data.SqlClient.SqlDataReader'
".
Thanks your help will be very much appreciated.
推荐答案
ExecuteNonQuery返回受操作影响的行数/记录数的整数。您需要使用ExecuteReader而不是使用ExecuteNonQuery。
ExecuteNonQuery - >主要用于更新,插入和删除。
ExecuteReader - >返回一个可以为Select语句加载记录的数据阅读器。
ExecuteScalar - >返回查询返回的第一个记录的第一列。用于计数,平均等
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.
这篇关于不能隐式地将类型'int'转换为'system.data.dataset'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!