我正在尝试从 sqlite 数据库填充列表视图。我的代码是
using (SQLiteConnection connection = new SQLiteConnection(@"Data Source=c:\MyProjects\SqliteTest\TestData.db"))
{
connection.Open();
SQLiteDataAdapter ad = new SQLiteDataAdapter();
SQLiteCommand cmd = new SQLiteCommand();
String str = "SELECT Name,Email FROM tblInfo";
cmd.CommandText = str;
ad.SelectCommand = cmd;
cmd.Connection = connection;
DataSet ds = new DataSet();
ad.Fill(ds);
myList.DataContext = ds.Tables[0].DefaultView;
connection.Close();
}
xaml 代码就像
<Grid>
<ListView x:Name="myList"
Height="100"
HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="300">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn>
<GridViewColumn Width="100" Header="Email" DisplayMemberBinding="{Binding Path=Email}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
没有错误,但列表为空。