|
|
|
VB.NET มันเกิด Error Object reference not set to an instance of an object. ช่วยดูให้หน่อยคับ ผมควรแก้ไขอย่างไร |
|
|
|
|
|
|
|
Code (VB.NET)
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
''''''''''''''''''''''''tran start'''''''''''''''''''''''
tran = conn.BeginTransaction()
comedit.Transaction = tran
tran.Begin()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim addpno As String
Dim addqty As Integer
Dim addprice As Integer
Dim checkpiece As Integer
Dim checkprice As Integer
Dim check As Integer
check = dgv.Rows.Count - 1
Try
For d = 0 To check
addpno = dgv.Rows.Item(d).Cells(0).Value.ToString
addqty = dgv.Rows.Item(d).Cells(2).Value
addprice = dgv.Rows.Item(d).Cells(3).Value
checkpiece = dgv.Rows.Item(d).Cells(4).Value
checkprice = dgv.Rows.Item(d).Cells(5).Value
'cut stock
Dim cutstock As String
cutstock = "update tbl_Products set ProdQty = '" & checkpiece - addqty & "' WHERE (ProdNo='" & addpno & "')"
With comedit
.CommandText = cutstock
.CommandType = CommandType.Text
End With
'make order
Dim makeorder As String
If RadioButton1.Checked = True Then
makeorder = "insert into tbl_Orders (OrdNo,CustNo,OrdDate,OrdTotal) VALUES (@a,@b,'" & Format(Now, "Short Date") & "',@c)"""
'('" & Label4.Text & "','" & ComboBox1.SelectedValue & "','" & Format(Now, "Short Time") & "','" & checkprice & "')"
With comedit
.CommandText = makeorder
.CommandType = CommandType.Text
End With
comedit.Parameters.AddWithValue("a", Label4.Text)
comedit.Parameters.AddWithValue("b", ComboBox1.SelectedValue)
comedit.Parameters.AddWithValue("c", FormatCurrency(checkprice))
MsgBox(FormatCurrency(checkprice))
Else
makeorder = "insert into tbl_Orders (OrdNo,CustNo,OrdDate,OrdTotal) VALUES (@a,'c0000','" & FormatDateTime(Now, DateFormat.ShortDate) & "',@b)"
'('" & Label4.Text & "','c0000','" & Format(Now, "Short Time") & "','" & checkprice & "')"
With comedit
.CommandText = makeorder
.CommandType = CommandType.Text
End With
comedit.Parameters.AddWithValue("a", Label4.Text)
comedit.Parameters.AddWithValue("b", FormatCurrency(checkprice))
MsgBox(FormatCurrency(checkprice))
End If
'make orderline
Dim orderline As String
orderline = "insert into tbl_Orderlines(OrdNo,ProdNo,Qty,Odl_Price) VALUES (@a,@b,@v,@d)"
'('" & Label4.Text & "','" & addpno & "','" & addqty & "', '" & addprice & "')"
With comedit
.CommandText = orderline
.CommandType = CommandType.Text
End With
comedit.Parameters.AddWithValue("a", Label4)
comedit.Parameters.AddWithValue("b", addpno)
comedit.Parameters.AddWithValue("c", addqty)
comedit.Parameters.AddWithValue("d", FormatCurrency(addprice))
Next
MsgBox(addpno)
tran.Commit() '''''''''Tran Commit'''''''''''''''''
MsgBox(addpno)
Dim a As Integer
a = comedit.ExecuteNonQuery()
MsgBox("บันทึกเสร็จสิ้น" & a, MsgBoxStyle.OkOnly, "AddOrders")
Catch ex As Exception
tran.Rollback() ''''''''''Tran Rollback'''''''''''''
MsgBox("ERROR : " & ex.Message, MsgBoxStyle.Critical, "ERROR")
End Try
End Sub
มันเกิด Error Object reference not set to an instance of an object.
ช่วยดูให้หน่อยคับ ผมควรแก้ไขอย่างไร
Tag : Ms Access, VS 2008 (.NET 3.x)
|
|
|
|
|
|
Date :
2012-03-25 03:37:17 |
By :
newstone |
View :
1525 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เกิดจาก Object ไม่ถูกต้องระหว่าง Runtime ครับ จะต้องใช้การ Debug ถึงจะรู้ครับ
|
|
|
|
|
Date :
2012-03-25 08:37:16 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|