我正在最糟糕的时候弄清楚这一点。我必须使用我还不完全理解的 MVVM,并将一个填充了 SQL 数据的列表绑定到 radGridView。听起来很容易......但我无法弄清楚。数据未显示,我认为这是因为我绑定错误。下面是我的相关代码。任何帮助,将不胜感激!
C# (HistoryAuditLogViewModel.cs):
#region Private Fields
private DatabaseConnectionSetting dbSetting;
private string tableName = "Manufacturers";
private int primaryKeyID = 1;
private string entryID;
private string manufacturerID;
private string manufacturerName;
private string auditDate;
private string sqlLogin;
private string application;
private string dbConnectionKey = Alliance.Infrastructure.Common.DatabaseConnectionSetting.BACKFLOW_SCOPE_KEY;
#endregion
public void Load_Audit()
{
string strSQLconnection = (dbSetting.SqlConnectionString + "; User Id = " + dbSetting.SqlUserName + "; Password = " + dbSetting.SqlPassword + ";");
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("SELECT [EntryID], [AuditValue].value('(row/@ManufacturerID)[1]', 'int') as ManufacturerID, [AuditValue] .value('(row/@ManufacturerName)[1]', 'nvarchar(50)') as ManufacturerName, [AuditDate], [SqlLogin], [Application] from [Backflow].[dbo].[AuditLog] where (TableName = @tableName AND [EntryID] = @primarykey)", sqlConnection);
sqlCommand.Parameters.AddWithValue("@tablename", tableName);
sqlCommand.Parameters.AddWithValue("@primarykey", primaryKeyID);
SqlDataReader reader = sqlCommand.ExecuteReader();
List<String> dataList = new List<String>();
while (reader.Read())
for (int i = 0; i < reader.FieldCount; i++)
{
string rdr = reader[i].ToString();
dataList.Add(rdr);
}
}
XAML (HistoryAuditLogView.xaml):
<telerik:RadGridView Name="AuditGrid" ItemsSource="{Binding dataList}">
</telerik:RadGridView>