0
我有以下代碼。我有一個Oracle查詢返回多行。我需要將數據填充到字典列表中,但是我遇到了一個問題,即該列表始終填滿最後一行重複的行。如何迭代每個Oracle行的列表。如何迭代字典字典列表?
代碼:
var list = new List<string>();
List<Dictionary<String, String>> listDic = new List<Dictionary<String, String>>();
using (var con = new OracleConnection(Config.EDLRDev))
{
var com = con.CreateCommand();
try
{
con.Open();
com.CommandText = "SELECT * FROM edlr_comm_rep_total a where a.dealer_id = 'wb-pos00289' and a.comm_type = 'Activation' ";
//com.Parameters.Add("msisdn", OracleDbType.Char).Value = msisdn;
Dictionary<String, String> objDic = new Dictionary<string, string>();
var reader = com.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string CommissionDealerId = reader[0].ToString();
string Month = reader[1].ToString();
string DealerCommissionType = reader[2].ToString();
string CommissionCount = reader[3].ToString();
string CommissionAmount = reader[4].ToString();
objDic["CommissionDealerId"] = CommissionDealerId;
objDic["Month"] = Month;
objDic["DealerCommissionType"] = DealerCommissionType;
objDic["CommissionCount"] = CommissionCount;
objDic["CommissionAmount"] = CommissionAmount;
listDic.Add(objDic);
}
}
reader.Close();
}
catch (Exception ex)
{
con.Dispose();
}
con.Dispose();
return listDic;
}
很好,非常感謝:) – Sereen