I am having some trouble getting my page running. I keep getting a NullException Error
and am not sure what to do to get my code to be able to run. Here is my current code.
Imports System.Data
Imports System.Data.SqlClient
Partial Class Proj_product
Inherits System.Web.UI.Page
Private Sub ProductDisplayValues(ByVal temp As String)
Dim SearchId As Int32 = Convert.ToInt32(temp) 'Searching for a product with this ID
Session("ProductPicID") = SearchId 'Record SearchID as a session variable
Dim myGlobal As New clsGlobal
'declare and open a connection to the Catalog table.
'Select the product with ID number equal to SearchID
Dim cnnSQL As New SqlConnection(myGlobal.cnnstring)
Dim cmd As New SqlCommand("Select PROD_NAME, PROD_PRICE, PROD_DESC from CATALOG Where PROD_ID = " & SearchId, cnnSQL)
Dim rdr As SqlDataReader
Try
cnnSQL.Open()
rdr = cmd.ExecuteReader()
If rdr.Read Then
lblName.Text = rdr(0) 'Read Name
lblPrice.Text = rdr(1) 'Read Price
'Change price format to 2 decimal places
lblPrice.Text = "$" & Mid(lblPrice.Text, 1, Len(lblPrice.Text) - 2)
txtDescription.Text = rdr(2) 'Read Description
End If
rdr.Close()
cnnSQL.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim CaptureId() As String
'ValueID is a collection of parameters passed from the catalog page
'by the Java code and the click event that we wrote for thumbnails
'In our case there is just one parameter: ID
Dim ValueID As System.Collections.Specialized.NameValueCollection
ValueID = Request.QueryString
'Retrieve parameter value from the collection and assign it to CaptureID
CaptureId = ValueID.GetValues("Id")
'Call procedure that displays product information
Call ProductDisplayValues(CaptureId(0).ToString) "Here is where the NullException Occurs"
End Sub
Private Sub btnReturnCatalog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReturnCatalog.Click
Response.Redirect("catalog.aspx")
End Sub
End Class