如何將system.data.datarow轉換爲整數?在asp.net DataRow轉換問題
我有它返回的,我想在可變 的整數聲明如下
int TotalRecords=ds.Tables[1].Rows[0];
這裏ds是數據集存儲記錄的計數一個數據行。
當我試圖寫它告訴我,我不能隱式轉換上述聲明的System.Data.DataRow爲int
如何將system.data.datarow轉換爲整數?在asp.net DataRow轉換問題
我有它返回的,我想在可變 的整數聲明如下
int TotalRecords=ds.Tables[1].Rows[0];
這裏ds是數據集存儲記錄的計數一個數據行。
當我試圖寫它告訴我,我不能隱式轉換上述聲明的System.Data.DataRow爲int
你需要轉換價值爲整數:
int TotalRecords = (int)ds.Tables[1].Rows[0]["YourColumnName"];
沒有相同的錯誤,它顯示「無法將數據行轉換爲int」 –
抱歉,編輯爲:int TotalRecords =(int)ds.Tables [1] .Rows [0] [「YourColumnName」]其中「YourColumnName」是您想要的值的列的名稱。 – saille
謝謝你......它包含了列名後爲我工作 –
嘗試,
int TotalRecords=ds.Tables[1].Rows[0].Count();
你必須包括LINQ的如果不是包括
using System.Linq;
我包括System.Linq但沒有定義方法「Count()」 –
System.Linq不是必需的 - 這是ADO.NET。 – saille
不要忘記將答案標記爲接受,如果你有你想要的信息...也可以upvote答案 –