2016-04-08 38 views
0

我得到一個錯誤1消息,指出」類型'布爾'的值不能轉換爲'System.Data.DataRow「。我做一個轉換值類型布爾值的System.Data.DataRow?試過,但無濟於事。類型'布爾'值不能轉換爲'System.Data.DataRow「

這裏是我的代碼

Dim newRow As DataRow 

newRow = Database51DataSet1.Tables(0).NewRow 
newRow.Item(0) = TextBox3.Text 
newRow = ("orderID") = (TextBox3.Text.Trim() = "0"(Convert.ToInt32(TextBox3.Text))) 
newRow.Item(1) = TextBox4.Text 
newRow.Item(2) = TextBox5.Text 
Database51DataSet1.Tables(0).Rows.Add(newRow) 
+0

你能解釋一下你在上面的代碼中的第四行的意圖? – Steve

+0

下一次,請告訴我們您在哪條線路上發生了錯誤。 –

回答

1

你不想給一個布爾值轉換爲DataRow,編譯器假設因爲比較返回Boolean而您將其指定爲newRow

我想你想分配OrderId字段值。所以替換...

newRow = ("orderID") = (TextBox3.Text.Trim() = "0"(Convert.ToInt32(TextBox3.Text))) 

Dim orderId As Int32 
If Int32.TryParse(TextBox3.Text.Trim(), orderId) Then 
    newRow("orderID") = orderId 
End If 

也可以用來處理這不是一個有效的整數的情況。

如果該列實際上是一個string,你要分配與價值前導零:

newRow("orderID") = TextBox3.Text.Trim().PadLeft(2, "0"c) 
+0

太棒了!有用。 –

相關問題