wpf中如何将datagrid控件绑定到数据库上呀
1个回答
展开全部
xaml中绑定:
<DataGrid Name="dataGrid1" >
<DataGridTextColumn Header="日期" Binding="{Binding Path=Date}"/>//table表中的字段
</DataGrid>
xaml.cs:
string con = "Provider=System.Data.SqlClient;Data Source=.;database=logistics;User ID=sa;Password=sa123";
SqlConnection sCon = new SqlConnection(con);
sCon .Open();
string sql = "select * from table";
DataTable dt = new DataTable();
SqlDataAdapter da=new SqDataAdapter(sql,sCon );
DataSet ds=new DataSet();
ds.Fill(ds,"dtName");
dataGrid1.ItemsSource = ds.Tables["dtName"].DefaultView;
<DataGrid Name="dataGrid1" >
<DataGridTextColumn Header="日期" Binding="{Binding Path=Date}"/>//table表中的字段
</DataGrid>
xaml.cs:
string con = "Provider=System.Data.SqlClient;Data Source=.;database=logistics;User ID=sa;Password=sa123";
SqlConnection sCon = new SqlConnection(con);
sCon .Open();
string sql = "select * from table";
DataTable dt = new DataTable();
SqlDataAdapter da=new SqDataAdapter(sql,sCon );
DataSet ds=new DataSet();
ds.Fill(ds,"dtName");
dataGrid1.ItemsSource = ds.Tables["dtName"].DefaultView;
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询