我的SQL Server查询中的WPF中的数据网格有问题。结果工作正常,但在我的数据网格中,它返回一些缺少值的空列。
这是我的SQL查询
SELECT
DATENAME(dw, CAST(DATEPART(m, TASK.Date) AS VARCHAR) + '-' +
CAST(DATEPART(d, TASK.Date) AS VARCHAR) + '-' +
CAST(DATEPART(yy, TASK.DATE) AS VARCHAR)) AS 'Day Name',
EMP.Employee_ID AS 'Employee ID',
EMP.Employee_LastName + ' ' + EMP.Employee_FirstName AS 'Employee Name',
TASK.Task_Assigned AS 'No. of Assigned Task',
TASK.Task_Completed AS 'No. of Completed Task',
TASK.Task_Remaining AS 'No. of Remaining Task',
TASK.Total_Tasks AS 'Total No. Of Tasks Including Lastweek',
CAST(Task.Date As DATE) AS 'Date'
FROM
[dbo].Employee_Table EMP
INNER JOIN
[dbo].Tasks_Table TASK ON EMP.Employee_ID = TASK.Employee_ID
输出就是这个
SQL Server 2012 Execute Query Output
但是在我的WPF应用程序中运行它之后,这就是我得到的
以下是我使用vb.net运行SQL查询的方法
Dim conn As SqlConnection = New SqlConnection("")
Dim sqlCommand As SqlCommand = New SqlCommand()
sqlCommand.CommandText = "[dbo].[DisplayTTM]"
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.Connection = conn
conn.Open()
sqlCommand.ExecuteNonQuery()
objDataAdapter = New SqlDataAdapter(sqlCommand)
objDataAdapter.Fill(ds, "TeamTaskManager")
dgrid_MyTTM.DataContext = ds
conn.Close()
这是我的datagrid wpf代码。
<DataGrid Name="dgrid_MyTTM" ItemsSource="{Binding Path=TeamTaskManager}" AutoGenerateColumns="True" IsReadOnly="True">
</DataGrid>
PS。当我使用ds.getXml()
时,我看到它从查询中获取值但不会在屏幕上输出它们。希望有人可以帮助我。感谢
答案 0 :(得分:0)
我已经找到了答案,我就这样做了
<DataGrid.Columns>
<DataGridTextColumn Header="Day" Binding="{Binding Path='a'}" />
<DataGridTextColumn Header="Employee ID" Binding="{Binding Path='b'}" />
<DataGridTextColumn Header="Employee Name" Binding="{Binding Path='c'}" />
<DataGridTextColumn Header="No. of Assigned Task" Binding="{Binding Path='d'}" />
<DataGridTextColumn Header="No. of Assigned Task Completed" Binding="{Binding Path='e'}" />
<DataGridTextColumn Header="No. of Assigned Task Remaining" Binding="{Binding Path='f'}" />
<DataGridTextColumn Header="Total No. of Task including Yesterday" Binding="{Binding Path='g'}" />
<DataGridTextColumn Header="Date" Binding="{Binding Path='h'}" />
</DataGrid.Columns>
突然把我的所有记录放在桌子上。谢谢你们。