我有两个数据库。第一个通过ListBox
示出,第二个通过ListView
示出。我希望能够基于所选的ListBox
元素在ListView
中显示一些信息,但我的代码不起作用。
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
是某种字符串,但事实并非如此。
SqlCommand command = new SqlCommand
($@"SELECT * FROM Employee WHERE Dep_nt="+
DpListBox.SelectedValue.ToString(),
connection);
请使用参数化存储过程内联查询是一种糟糕的做法