C# ';数据网格&x27;不包含';数据源';
试图从组合框中获取要显示在我的数据网格中的选定值时遇到问题。首先,我使用的是Systems.Windows.Forms的引用。看了教程后,似乎C# ';数据网格&x27;不包含';数据源';,c#,sql-server,database,wpf,C#,Sql Server,Database,Wpf,试图从组合框中获取要显示在我的数据网格中的选定值时遇到问题。首先,我使用的是Systems.Windows.Forms的引用。看了教程后,似乎.DataSource不起作用 private void CustomerID_TextChanged(object sender, TextChangedEventArgs e) { if (customerCombo.Text == "CUS_ID") { SqlConnection con = new SqlConne
.DataSource
不起作用
private void CustomerID_TextChanged(object sender, TextChangedEventArgs e)
{
if (customerCombo.Text == "CUS_ID")
{
SqlConnection con = new SqlConnection("Data Source = xmsql04.australiaeast.cloudapp.azure.com,6302 ;Initial Catalog=DAD_TruckRental_RGM;Persist Security Info=True;User ID=DDQ4_Melveena;Password=fBit$73939");
SqlDataAdapter sda = new SqlDataAdapter("SELECT RentalId,TruckId,CustomerID,TotalPrice FROM Truckrental where CustomerID like'"+CustomerID.Text+"%'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
customerDataGrid.DataSource = dt;
}
它将显示此错误:
“DataGrid”不包含“DataSource”的定义,并且没有接受第一个
找不到类型为“DataGrid”的参数(是否缺少使用
指令或程序集引用?)ProjectDAD C:\Users\Little
Grace\Desktop\ProjectDAD\RentalManagement\displayInfo.xaml.cs 73活动
在WPF中,它是,并且在WPF中,您需要使用:
customerDataGrid.ItemsSource = dt.DefaultView;