簡體   English   中英

與數據表綁定時在datagridview中顯示空行

[英]showing empty rows in datagridview while binding with datatable

我從SQL Server數據庫中檢索數據,並將數據填充到數據表中(結果具有4行)。 然后與datagridview綁定。 它創建了四行,但是所有行都有空單元格。

綁定碼

        dt = newconnection.selectcommand("Select row_number() over(order by Join_Date) as sno , Employee_Name as empname,  REPLACE(CONVERT(CHAR(11), Join_Date, 106) ,' ','-') as doj,'" + billing_month + "' as \"billingmonth\" ," + noofdaysmonth + "  as daysofmonth ,'" + attndperiod + "'  as period, Rate as rate, 0 as billabledays from Employee_For_Customer where Customer_Name = '" + CmbCustomer.Text + "'");           
        DgvEmployee.AutoGenerateColumns = false;
        DgvEmployee.DataSource = dt;

綁定數據源之前

綁定數據源后

我也有這個麻煩。 我正在使用SPROC。 我在datagridview中有預定義/預設計的列。

我忘記為列設置DataPropertyName屬性。

我認為這一切都會匹配,因為列的名稱與我的數據源中的列的名稱相匹配,但是顯然它並不那么聰明.. :-(

在此處輸入圖片說明

所以我的代碼看起來像這樣:

private TimeSheetEntities db = new TimeSheetEntities();

private void button1_Click(object sender, EventArgs e)
{
  var recs = db.usp_ADMIN_SelectExistingSites();
  dgExistingSites.AutoGenerateColumns = false;
  dgExistingSites.DataSource = recs.ToList();
}

暫無
暫無

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

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