我想从.mdf数据库文件中使用ListView显示数据库内容。这里是我使用的代码块:ListView和数据库
connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=database.mdf;Integrated Security=True");
SqlDataAdapter dataAdapter;
DataTable table;
SqlCommand command;
command = new SqlCommand("SELECT * FROM movies", connection);
dataAdapter = new SqlDataAdapter(command);
table = new DataTable();
dataAdapter.Fill(table);
moviesListView.ItemsSource = table.DefaultView;
而这是行不通的。我也尝试了DataContext而不是ItemsSource,但它没有帮助。另一方面,当我使用DataGrid时,它工作正常。
请问您能解释一下原因吗?
Regards, Vitalii。
什么你做 意思是_not working_?您收到异常或错误讯息? – 2014-12-06 18:02:01
只是看不到内容(ListView为空)。 – witua 2014-12-06 18:03:52
愚蠢的问题:但是,你是否检查'table'是否实际上包含任何行? – 2014-12-06 18:06:06