[英]Conversion from string “Price” to type 'Integer' is not valid
使用vb asp.net
error:
數據庫(2)有問題。 從字符串“ Price”到類型“ Integer”的轉換無效。
Dim testP As Decimal = reader3.GetDecimal("Price")
列價格是數據庫中的小數
GetDecimal
方法僅接受列序號,而不接受列名。 正確的選擇是獲取該名稱的序數:
Dim testP As Decimal = reader3.GetDecimal(reader3.GetOrdinal("Price"))
或者,您可以只從Item
屬性獲取Object
引用並將其強制轉換為:
Dim testP As Decimal = CDec(reader3("Price"))
這有效
Dim testP As Decimal = Decimal.Parse(reader3("Price").ToString())
將int轉換為十進制
Convert.ToDecimal(reader3("Price").ToString());
嘗試使用檢索到的列的索引。 說您的Select看起來像這樣
Select Name, Department, Item, Price From MyTable;
然后,價格將為索引3。(基於零)
Dim testP As Decimal = reader3.GetDecimal(3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.