我有两个数据库。第一个通过ListBox
显示,第二个通过ListView
显示。我希望能够根据所选的ListView
元素在ListBox
中显示一些信息,但是我的代码无法正常工作。
private void DpListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
L.InitReadOnly(false, NameF, LastNameF, AgeF, DepartmentF, ProfessionF, SalaryF);
L.InitReadOnly(false, Name4, LastName4, Age4, Department4, Profession4, Salary4);
int counter = 0;
IEnumerable<Employee> critCareEmp;
critCareEmp = L.EmpUpdate(counter, Emp, DpListBox, Ep);
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter();
Console.WriteLine(DpListBox.SelectedValue.ToString());
SqlCommand command = new SqlCommand($@"SELECT * FROM Employee WHERE Dep_nt={DpListBox.SelectedValue}", connection);
adapter.SelectCommand = command;
DataTable dataTable1 = new DataTable();
adapter.Fill(dataTable1);
Ep.ItemsSource = dataTable1.DefaultView;
}
似乎我需要DpListBox.SelectedValue
是某种字符串,但不是。
答案 0 :(得分:0)
SqlCommand命令=新的SqlCommand($ @“ SELECT * FROM Employee WHERE Dep_nt =” + DpListBox.SelectedValue.ToString(),connection);
请使用参数化存储过程 内联查询是一种糟糕的做法