Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';数据网格&x27;不包含';数据源';_C#_Sql Server_Database_Wpf - Fatal编程技术网

C# ';数据网格&x27;不包含';数据源';

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

试图从组合框中获取要显示在我的数据网格中的选定值时遇到问题。首先,我使用的是Systems.Windows.Forms的引用。看了教程后,似乎
.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;