Asp.Net VB help

Hi

I've got some code that is suppose to set a session variable and name a textbox depending on whether the record set is populated or not but its not working.

I don't get any errors but it just does nothing whether the recorded is populated or not.   Can someone tell me why?

While objComp3.Read()

            If objComp3("TRAINEEID") IsNot Nothing Then

                Session("IQAComplianceMode") = "Update"

                btnComplianceButton.Text = "Update Complance"

            Else

                Session("IQAComplianceMode") = "Insert"

                btnComplianceButton.Text = "Add Complance"
            End If

            labeltest.text = objComp3("TRAINEEID").ToString

            End While

Open in new window

EdAsked:
Who is Participating?
 
EdAuthor Commented:
Final Solution is


        While objComp3.Read()

            If objComp3("TRAINEEID") = DBNull.Value Then

                Session("IQAComplianceMode") = "Update"
                btnComplianceButton.Text = "Update Complance"

            Else



                Session("IQAComplianceMode") = "Insert"
                btnComplianceButton.Text = "Add Complance"



            End If
            End While

Open in new window

0
 
Lokesh B RDeveloperCommented:
Hi,

Where is your query which is populating this SqlDataReader?
can you share the full code for this method.

Check this code

If objComp3.HasRows Then
	If objComp3.Read() Then
		If objComp3("TRAINEEID") IsNot Nothing Then
			Session("IQAComplianceMode") = "Update"
			btnComplianceButton.Text = "Update Complance"
		Else
			Session("IQAComplianceMode") = "Insert"
			btnComplianceButton.Text = "Add Complance"
		End If

		labeltest.text = objComp3("TRAINEEID").ToString()
	End If
End If

Open in new window

0
 
EdAuthor Commented:
Here the whole code

            '' Load IQA COmplance''''''''''''

            Dim CompGetCOnn As SqlConnection
            Dim ComGetComm As SqlCommand
            Dim objComp3 As SqlDataReader
            Dim connectionStringIQA As String = ConfigurationManager.ConnectionStrings("IRISConnectionString").ConnectionString
            CompGetCOnn = New SqlConnection(connectionStringIQA)
            ComGetComm = New SqlCommand()

            ComGetComm.Connection = CompGetCOnn

            ComGetComm.CommandType = CommandType.StoredProcedure

            ComGetComm.CommandText = "GET_IQA_Compliance"

            ComGetComm.Parameters.Add("@IVRECORDID", SqlDbType.Int).Value = GridIVRecs.SelectedDataKey.Value

            CompGetCOnn.Open()
            objComp3 = ComGetComm.ExecuteReader()

            While objComp3.Read()

            If objComp3("TRAINEEID") IsNot Nothing Then

                Session("IQAComplianceMode") = "Update"

                btnComplianceButton.Text = "Update Complance"

            Else

                Session("IQAComplianceMode") = "Insert"

                btnComplianceButton.Text = "Add Complance"
            End If

            labeltest.text = objComp3("TRAINEEID").ToString

            End While

            objComp3.Close()
            CompGetCOnn.Close()


        tcIQADetail.ActiveTabIndex = 0

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Lokesh B RDeveloperCommented:
Hi,

Did you try my code?

keep break point and see whether you have rows in reader.
0
 
EdAuthor Commented:
I tried the code you posted but still the same.
0
 
EdAuthor Commented:
keep break point and see whether you have rows in reader.

How do I do that?
0
 
Lokesh B RDeveloperCommented:
Hi,

Right Click on the below line and Select Breakpoint and Select Insert break point and see whether it goes inside the loop or not.

If objComp3.HasRows Then

Run the application and see
http://csharp.net-tutorials.com/debugging/breakpoints/
0
 
EdAuthor Commented:
Found the correct code to use after stepping through code, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.