簡體   English   中英

WPF DataGrid .NET框架4

[英]WPF DataGrid .NET framework 4

我在使用DataGrid的WPF中遇到問題,正在使用SQLDataReader,當我將記錄從Datatable填充到Datagrid時,沒有記錄,但是hasRows是我的代碼。

try
{
    string commandText = "dbo.sp_select_survey";
    SqlConnection conn = new SqlConnection("Data Source=IT-PC1;Initial Catalog=gcserp;User ID=test;Password=test;Initial Catalog=gcserp;Integrated Security=True");

    SqlCommand cmd = new SqlCommand(commandText, conn);
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.CommandTimeout = 600;

    conn.Open();

    SqlDataReader objRDR = cmd.ExecuteReader((CommandBehavior.CloseConnection));

    DataTable dt = new DataTable();
    dt.Load(objRDR);

    dataGrid1.ItemsSource=dt.DefaultView;            
}
catch
{           
}

不確定您的aspx頁面是什么樣子以及datagrid中的設置是什么,但是我將首先測試datagrid而不定義任何boundcolumns或customtemplate列,並確保將autogeneratecolumns設置為true。 就像一些基本的東西一樣,看看您的數據是否將綁定到網格:

<asp:datagrid id="dataGrid1" runat="server" />

還要確保您沒有返回任何空值,並在查詢中包含ISNULL(field,'')。

最后,在.net framework 4中,您應該使用gridview而不是datagrid ...不確定是否是錯字。

我認為您應該輸入以下內容之一:
Integrated Security = true User ID = "" and Password = "" '

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM