0
我有一個Windows窗體,我試圖插入數據從列表框到一個SQL函數我認爲它傳遞的是數據,但在我的函數中的某處它不寫數據我的桌子有什麼想法?當我通過數據步驟,它看起來像它會通過函數,直到if語句它不將數據添加到表SQL不向表中添加數據
'this is the data being passed in
DataConnection.addOrder(Date.Now, totalPizzas, totalDrinks, total)
Public Function addOrder(
orderDate As Date,
orderPizzaTotals As Integer,
orderDrinkTotals As Integer,
orderPriceTotal As Decimal
) As Boolean
Dim cmd As New SqlCommand
cmd.CommandText = String.Format(
"INSERT INTO dbo.[Order] (
orderDate, orderPizzaTotals, orderDrinkTotals, orderPriceTotal)
VALUES ('{0}','{1}','{2}','{3}');",
orderDate, orderPizzaTotals, orderDrinkTotals,orderPriceTotal
)
cmd.Connection = con
If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
Dim results = cmd.ExecuteNonQuery()
If results > 0 Then
Return True
Else
Return False
End If
End Function
你確定沒有錯誤嗎?它看起來像試圖將數字數據作爲字符串插入到SQL語句中。 – David 2014-09-21 20:20:04
修改代碼以構建SQL語句並將其存儲在變量中。單步執行代碼並檢查生成的SQL,將其複製到DB編輯器窗口並執行語句。發佈您收到的任何錯誤消息。 – Tony 2014-09-21 20:42:43