private void table_loader()
{
SqlCeConnection ucon = new SqlCeConnection();
ucon.ConnectionString = " Data Source=C:\\Documents and Settings\\laser\\My Documents\\Visual Studio 2008\\Projects\\dbtest\\dbtest\\ulist.sdf";
ucon.Open();
SqlCeCommand uce = new SqlCeCommand();
SqlCeDataAdapter uced = new SqlCeDataAdapter();
uced.SelectCommand = new SqlCeCommand("SELECT * FROM plist", ucon);
uced.Fill(ulistDataSet, "plist");
DataTable dplist = ulistDataSet.Tables["plist"];
for (int i = 0; i <dplist.Rows.Count;i++)
{
DataRow drow = dplist.Rows[i];
ListViewItem lvi = new ListViewItem(drow["Process"].ToString());
MessageBox.Show(lvi.Text);
listView2.Items.Add(lvi);
}
}
我使用上面的代码在listview中显示数据库(SQL Server CE 3.5)值,但listview没有显示任何内容!消息框()在循环执行时逐个正确地显示数据库值,我认为问题必须在于向listview添加值。扫管笏这个代码有问题,任何人都可以解释一下吗?抱歉我的英语很差!
提前谢谢, Ulaga答案 0 :(得分:1)
尝试使用此代码
listView2.Items.Add(drow["Process"].ToString()); //Verify that column's name is Process
使用foreach语法回答
foreach(var row in dplist.Rows)
{
listView2.Items.Add(row["Process"].ToString());
}
答案 1 :(得分:1)
很难确切地说项目添加代码看起来很好
你可以试试:
1.在列表视图中添加列(listView2.Columns.Add("Item Column", -2, HorizontalAlignment.Left);)
2.将列表视图切换到详细信息模式listView2.View = View.Details;
查看来自msdn - http://msdn.microsoft.com/en-us/library/system.windows.forms.listview(v=vs.100).aspx
的样本