簡體   English   中英

從數據庫ASP中獲取數據時從表中跳過行。 凈C#

[英]skipping rows from table while fetching data from database asp. net C#

fees_structure有24個“ A”類別行。 但是當我嘗試獲取它們並打印時,它僅顯示20或(有時為21行)

這是我的代碼:

string catA = "SELECT id,fees_name,amount,fee_category FROM fees_structure where fee_category='A' ORDER BY id";

using (SqlCommand scom = new SqlCommand(catA, con))
{
    using (SqlDataReader read = scom.ExecuteReader())
    {
        read.Read();

        if (read.HasRows)
        {
            while (read.Read())
            {
                feestableA.Append("<tr>");
                feestableA.Append("<td>" + read["fees_name"] + "</td>");
                feestableA.Append("<td>" + read["amount"] + "</td>");
                feestableA.Append("</tr>");
            }

            plcfeesA.Controls.Add(new Literal { Text = feestableA.ToString() });
            plcfeesA.Dispose();
        }
    }
}

while之前的read()可疑。 我懷疑那是一排。

丟失行的另一種可能性是區分大小寫的排序規則-如果類別可以是'a' (或另一種編碼的變體)。 但是,這取決於用於列,數據庫和服務器的默認或顯式排序規則。

我不認為這是C#問題。

嘗試這個

string catA = "SELECT id,fees_name,amount,fee_category FROM fees_structure where fee_category like '%A%' ORDER BY id";

只要看看你的結果是否改變

嘗試這個。 仔細觀察,我刪除了執行您不想做的事情的代碼行。

string catA = "SELECT id,fees_name,amount,fee_category FROM fees_structure where fee_category='A' ORDER BY id";

using (SqlCommand scom = new SqlCommand(catA, con))
{
    using (SqlDataReader read = scom.ExecuteReader())
    {
        while (read.Read())
        {
            feestableA.Append("<tr>");
            feestableA.Append("<td>" + read["fees_name"] + "</td>");
            feestableA.Append("<td>" + read["amount"] + "</td>");
            feestableA.Append("</tr>");
        }

        plcfeesA.Controls.Add(new Literal { Text = feestableA.ToString() });
    }
}

}

暫無
暫無

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

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