C# - 在列表框中为每个项运行SQL查询

时间:2014-08-01 19:54:58

标签: c# sql wpf oracle listbox

我有一个通过Oracle数据库中的SQL查询填充项目的列表框。我希望能够为列表框中的每个项目的值运行单独的SQL查询,并使用返回的值填充单独的列表框。

    string sql2 = "select unique apps.fnd_application_all_view.application_name, fnd_responsibility_vl.responsibility_name, fnd_form_functions_tl.user_function_name, fnd_form_functions.function_name, fnd_form_functions_tl.description, fnd_form_functions.type FROM fnd_compiled_menu_functions, fnd_form_functions, fnd_form_functions_tl, fnd_responsibility, fnd responsibility_vl, apps.fnd_application_all_view WHERE fnd_compiled_menu_functions.function_id = fnd_form_functions.function_id AND fnd_responsibility.menu_id = fnd_compiled_menu_functions_menu_id AND fnd_responsibility_vl.responsibility_id = fnd_responsibility.responsibility_id AND fnd_form_functions.function_id = fnd_form_functions_tl.function_id AND apps.fnd_application_all_view.application_id(+) = fnd_responsibility.application_id AND fnd_responsibility.end_date is NULL AND fnd_responsibility_vl.end_date is NULL AND source_lang = 'US' AND fnd_responsibility_vl.responsibility_name = '" + lstResponsibilities.Items + "'";



                using (OracleDataAdapter da = new OracleDataAdapter(sql2, conn))
                {

                    lstResponsibilities.DisplayMember = "Responsibility_Name";
                    lstResponsibilities.ValueMember = "Responsibility_Name";
                    DataTable dt = new DataTable("Function_Name");
                    foreach (DataRow row in dt.Rows)
                    {
                        object[] objCollection = new object[lstResponsibilities.Items.Count];
                        lstResponsibilities.Items.CopyTo(objCollection, 0);
                        MessageBox.Show((objCollection[0] as DataRowView)[1] as string);
                    }

我想循环遍历lstResponsibilities中的项目(“Responsibility_Name”)并填充另一个列表框lstFunctions,并在查询中选择“Function_Name”。

我知道我在做一些大错的事 - 有人能帮我走上正确的轨道吗?

提前致谢。

0 个答案:

没有答案