Reputation: 103
I got this error when I click on SAVE button inside the save button is The error is
"Object reference not set to an instance of an object"
Protected Sub btnWizardFinish_Click(sender As Object, e As EventArgs)
If (rdoAprovalList.SelectedIndex = 1) Then
SaveConsideration(4)
Else
SaveConsideration(1)
End If
End Sub
and this is save sub that contain to save and update a value in DocumentStatusID field in Database
Private Sub SaveConsideration(ByVal DocumentStatusID As Integer)
Dim Conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand
Try
If ((txtProducerID.Text.Trim.Length = 9)) Then
cmd.Connection = Conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "spConsiderationSaving"
cmd.Parameters.AddWithValue("@libDocumentID", txtProducerID.Text)
cmd.Parameters.AddWithValue("@ProducerComments", txtProducerComment.Text)
cmd.Parameters.AddWithValue("@DocumentStatusID", DocumentStatusID)
cmd.Parameters.AddWithValue("@ConProduceThai", chkConproduceThai.Checked)
cmd.Parameters.AddWithValue("@ConProducePolicy", chkConProducePolicy.Checked)
cmd.Parameters.AddWithValue("@ConProduceIP", chkConProduceIP.Checked)
cmd.Parameters.AddWithValue("@ConProduceDanger", chkConProduceDanger.Checked)
cmd.Parameters.AddWithValue("@ConProducePeople", chkConproducePeople.Checked)
cmd.Parameters.AddWithValue("@ConProduceManage", chkConProduceManage.Checked)
cmd.Parameters.AddWithValue("@ConProduceMade", chkConProduceMade.Checked)
Conn.Open()
Dim ResponseText As Integer = DirectCast(cmd.ExecuteScalar, Int32).ToString
If (ResponseText = 1) Then
lblResponseResult.Text = "<img src='../images/icons/message-boxes/confirmation.png' /> บันทึกลงฐานข้อมูลเรียบร้อยแล้ว"
If (DocumentStatusID = 3) Then 'Goto next step
AlertRedirects("redirect", pnlHint.ClientID, 3, "Verification.aspx")
Else
AlertBoxs("alert", pnlHint.ClientID, 2)
End If
End If
Else
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("javascript:history.back();return false;")
sb.Append("};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "back", sb.ToString())
End If
Catch ex As Exception
Response.Write("Error Save: " & ex.Message)
Finally
Conn.Close()
End Try
End Sub
I think it's a problem with reference to something
Upvotes: 0
Views: 207
Reputation: 130
what is the error please specify that. the code which you posted in that is seems two syntax mistakes
Dim ResponseText As Integer = DirectCast(cmd.ExecuteScalar, Int32).ToString
If (ResponseText = 1)
you are assigning ResponseText a string value which is an integer
and second is if condition there should be double equals like If (ResponseText == 1)
because it's not assignment single equals used for assignment
Upvotes: 2