deNZity
asked on
error during for loop
I have the following loop
i = 0
For i = 0 To 7
If (Not requests(i).Equals(System. DBNull.Val ue)) Then
request = requests(i)
Dim sql1 As String = " insert request_items ([req_id], [request]) select max(req_id), '" & request & "' from requests "
Dim myCommand1 As New SqlCommand(sql1, myConnection)
myCommand1.ExecuteNonQuery ()
End If
Next
which gives me this error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
Line 62: i = 0
Line 63: For i = 0 To 7
Line 64: If (Not requests(i).Equals(System. DBNull.Val ue)) Then
Line 65: request = requests(i)
Line 66: Dim sql1 As String = " insert request_items ([req_id], [request]) select max(req_id), '" & request & "' from requests "
Source File: C:\Inetpub\loans\MemberPag es\Request .aspx.vb Line: 64
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Request.Button1_Click(Obje ct sender, EventArgs e) in C:\Inetpub\loans\MemberPag es\Request .aspx.vb:6 4
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +105
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +107
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +7
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +33
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +5102
i = 0
For i = 0 To 7
If (Not requests(i).Equals(System.
request = requests(i)
Dim sql1 As String = " insert request_items ([req_id], [request]) select max(req_id), '" & request & "' from requests "
Dim myCommand1 As New SqlCommand(sql1, myConnection)
myCommand1.ExecuteNonQuery
End If
Next
which gives me this error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
Source Error:
Line 62: i = 0
Line 63: For i = 0 To 7
Line 64: If (Not requests(i).Equals(System.
Line 65: request = requests(i)
Line 66: Dim sql1 As String = " insert request_items ([req_id], [request]) select max(req_id), '" & request & "' from requests "
Source File: C:\Inetpub\loans\MemberPag
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Request.Button1_Click(Obje
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the error points to this line
Line 64: If (Not requests(i).Equals(System. DBNull.Val ue)) Then
Line 64: If (Not requests(i).Equals(System.
put a line break inside the loop in
request = requests(i)
and see if it ever reaches that. if it does, press F5 to run the next loop, and so on, until you can determine on which loop the error is.
request = requests(i)
and see if it ever reaches that. if it does, press F5 to run the next loop, and so on, until you can determine on which loop the error is.
maybe try changing that line
If (Not requests(i).Equals(System. DBNull.Val ue)) Then
to this:
If (requests(i) IsNot System.DBNull.Value) Then
If (Not requests(i).Equals(System.
to this:
If (requests(i) IsNot System.DBNull.Value) Then
or if you are using 2003,
If (Not requests(i) Is System.DBNull.Value) Then
If (Not requests(i) Is System.DBNull.Value) Then
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all the replies found the problem.
I hadn't assigned values to the array :(
once I did that evrything works fine.
ok if I split points for replying?
I hadn't assigned values to the array :(
once I did that evrything works fine.
ok if I split points for replying?
Not a problem by me. ;=)
ASKER
Yes array holds 8 itmes
Dim requests(8) As String