我正在尝试使用以下代码在数据库的表中插入:
If MsgBox("Do you want to save '" & Me.TxtItemID.Text & "' & '" & Me.TxtRetail.Text & "'", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "(NS) - Save?") = MsgBoxResult.Yes Then
Me.asInsert.SaveValueIN("INSERT INTO LUP_ITEMSZM (nCODE, sITEM_DESC, nUNIT_COST, nSTOCK, nUNIT_PRICE, sPIECE_DESC, sPIECE_PACK, sSTATUS , sSupplier_NAME) VALUES(@nCode, @sITEM_DESC, , @nUNIT_COST,@nSTOCK, @nUNIT_PRICE, @sPIECE_DESC,@sPIECE_PACK, @sSTATUS, @sSupplier_NAME)")
SqlInsertCommand1.Parameters.Add(New SqlParameter("@nCODE", SqlDbType.BigInt)).Value = Me.TxtItemID.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@sITEM_DESC", SqlDbType.NVarChar)).Value = Me.txtItemDesc.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@nUNIT_COST", SqlDbType.Money)).Value = Me.TxtCost.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@nSTOCK", SqlDbType.BigInt)).Value = Me.TxtQtyStock.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@nUNIT_PRICE", SqlDbType.Money)).Value = Me.TxtRetail.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@sPIECE_DESC", SqlDbType.NVarChar)).Value = Me.TxtPcsDesc.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@sPIECE_PACK", SqlDbType.NVarChar)).Value = Me.TxtPPP.Text.Trim
SqlInsertCommand1.Parameters.Add(New SqlParameter("@sSTATUS", SqlDbType.NVarChar)).Value = Me.DmnStatus.SelectedIndex
SqlInsertCommand1.Parameters.Add(New SqlParameter("@sSupplier_NAME", SqlDbType.NVarChar)).Value = Me.CmbSupplier.SelectedItem.col1
Me.TxtItemID.Focus()
End If
我一直收到以下错误:
必须声明标量变量@ncode
请你的帮助
谢谢
答案 0 :(得分:0)
简单。 @ncode区分大小写。尝试在使用标量的插入查询中给出@nCODE而不是@ncode。
Me.asInsert.SaveValueIN("INSERT INTO LUP_ITEMSZM (nCODE, sITEM_DESC, nUNIT_COST, nSTOCK, nUNIT_PRICE, sPIECE_DESC, sPIECE_PACK, sSTATUS , sSupplier_NAME) VALUES(@nCODE, @sITEM_DESC, , @nUNIT_COST,@nSTOCK, @nUNIT_PRICE, @sPIECE_DESC,@sPIECE_PACK, @sSTATUS, @sSupplier_NAME)")
添加参数时,您将添加为@nCODE,而在插入查询中,您将其用作@ncode。两者都应该是一样的。
SqlInsertCommand1.Parameters.Add(New SqlParameter("@nCODE", SqlDbType.BigInt)).Value = Me.TxtItemID.Text.Trim