我对一些C#代码有一个非常奇怪的问题。 我有这样的方法:
public static void LoadDataToList(string viewName, ListBox lbxToLoad)
{
try
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = DBConnection.EnsureConnectionToDB();
cmd.CommandText = "select * from " + viewName;
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
List<CustomTypes.ListBoxItems> listItems = new List<CustomTypes.ListBoxItems>();
while (dr.Read())
{
var itemValue = dr.GetOracleValue(0);
var itemText = dr.GetOracleValue(1);
listItems.Add(new CustomTypes.ListBoxItems() { Value = itemValue, Text = itemText });
}
lbxToLoad.DisplayMemberPath = "Text";
lbxToLoad.ItemsSource = listItems;
lbxToLoad.IsEnabled = true;
dr.Dispose();
cmd.Dispose();
}
catch
{
MsgHandling(3);
}
}
有时当我在while (dr.Read())
中运行时,我收到错误ORA-01001。但正如你所看到我不使用过程命令类型...它是从视图中简单的选择查询。在视图中没有光标。任何想法发生了什么?
修改
查看SQL
select distinct
ti.value as id
, ti.value as value
from
x.table1 t
, x.table2 ti
WHERE
t.t1_num= ti.t2_num AND ti.type_id = 20003
ORDER by
ti.value asc;