如何将数据从表加载到IDictionary [英] How to load data from table into IDictionary
本文介绍了如何将数据从表加载到IDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我想问你一个问题.
我有一个包含一些数据的表,我想将这些数据加载到IDictionary中.我该怎么办.. ??
我正在使用oracle作为数据库,以及如何执行这样的sql语法:
Hi all, i wanna ask you something.
I have a table that contain some data and i want to load these into IDictionary. How can i do that..??
I''m using oracle as database, and for how i execute sql syntax like this :
public IDictionary<int, string> LOAD_DATA_TEMP_MSGS(string membercode, string status)
{
IDictionary<int, string> TEMP = new Dictionary<int, string>();
oConHandler = new CConnectionHandler();
try
{
oCommand = new OracleCommand(Q_SELECT_ALL_FROM_TABLE(membercode, status), oConHandler.OpenConnAkses());
oCommand.ExecuteScalar(); // Execute sql syntax
//-- load into Idictionary
//-- How can i do that ???
}
catch (Exception ex)
{
olog.WriteLogFile("Error while execute load_data_temp_msgs at : " + DateTime.Now.ToString() + "\n" + "Reason : " + ex.Message);
}
finally { oConHandler.CloseConnAkses(); }
return TEMP;
}
private string Q_SELECT_ALL_FROM_TABLE(string membercode, string status)
{
string Q_SQL = "SELECT * FROM T_MEMBER WHERE BANKCODE='" + membercode + "' AND STATUS='" + status + "'";
return Q_SQL;
}
推荐答案
我不相信您要为此使用ExecuteScalar.执行标量将仅返回一个值(数据集第一行的第一列,其他所有内容均被忽略).我认为ExecuteReader是您想要的.
我认为类似的方法可能会起作用:
I don''t believe you want to use ExecuteScalar for this. Execute scalar will only return a single value (first column of first row of dataset with everything else being ignored). I think ExecuteReader is what you want.
I think something like this might work:
using(OracleDataReader reader = oCommand.ExecuteReader()) //Instead of oCommand.ExecuteScalar;
{
while(reader.read)
{
TEMP.Add(Convert.ToInt32(reader.Item("{the name of column containing int value}"),reader.Item("{the name of column containing string}").ToString());
}
}
这篇关于如何将数据从表加载到IDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文