【发布时间】:2014-09-26 23:12:44
【问题描述】:
问题是,当我填充数据网格时,它会显示数据库中可用的行数,但行中的数据在数据网格中是空的。这是一个sn-p:
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
connection.Open();
SqlCommand command = new SqlCommand();
command.CommandText = "select item_name from prod_info";
cmdd.Connection = connection;
Datatable table= new Datatable();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(table);
dataGrid1.ItemsSource = table.DefaultView;
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是这里的 xaml 代码:
<DataGrid AutoGenerateColumns="False" Height="308" HorizontalAlignment="Left" Margin="59,89,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="502" ItemsSource="{Binding }"/>
【问题讨论】:
-
表到底是什么,一个DataSet?
-
@Juan 它是一个数据表...我是更正...现在检查一下。