Object reference not set to an instance of an object

L

Laura K

Hi.

I am trying to put a drop down in a repeater. I had this working in
dreamweaver but now I am trying to transfer it into VS. I am obviously
missing something. I am getting the following error.

"Object reference not set to an instance of an object"

THe error is referring to the following line which is located in the
function below.
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)

Can anyone shed some light?


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strProductCode = Request.QueryString("strProductCode")

'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_GetRelationshipProducts",
connection)
command.CommandType = CommandType.StoredProcedure


' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.NVarChar)
command.Parameters("@strProductCode").Value = strProductCode

' Create SqlDataAdapter and DataSet
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetPRoducts As New DataSet
mySqlDataAdapter.Fill(dsGetPRoducts, "products")

'create second table from second stored Proc.

Dim command2 As New SqlCommand("New_GetRelationshipColors",
connection)
command2.CommandType = CommandType.StoredProcedure
Dim mySqlDataAdapter2 As SqlDataAdapter = New
SqlDataAdapter(command2)
mySqlDataAdapter2.Fill(dsGetPRoducts, "colors")
dsGetPRoducts.EnforceConstraints = False

Repeater1.DataSource = dsGetPRoducts.Tables("products")
Repeater1.DataBind()

dsGetPRoducts.Relations.Add("ColorRelation",
referenceDataSet.Tables("Products").Columns("intProductId"),
referenceDataSet.Tables("Sizes").Columns("intProductId"))


End Sub

Function GetChildRows(ByVal dataItem As Object, ByVal relation As
String) As DataView


Dim drv As DataRowView = CType(dataItem, DataRowView)
If (Not drv Is Nothing) Then
' extracting the ProductId from the current row item
Dim intproductId As Int32 =
Convert.ToInt32(drv("intProductId"))
' filtering reference dataset to get the specific Product
row
' which also gets all the Color rows for this Product
Dim view As New DataView(dsGetProducts.Tables("Products"),
"intProductId = " & intproductId, "intProductId",
DataViewRowState.CurrentRows)
' the one and only Product for that ProductId
criteria/filter
Dim productRow As DataRowView = view(0)

' this is where the 'child rows' of colors are retrieved
for the Product
' in question
Return productRow.CreateChildView(relation)
End If

Return Nothing

End Function


The HTML is

<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container, "DataItem.IntProductID") %>
</td>
<td>
<%# Container.DataItem("strProductName") %>
</td>
<td>
<asp:dropdownlist DataSource='<%# GetChildRows( Container.DataItem,
"ColorRelation" ) %>' Runat="server" DataTextField="strColorID">
</asp:dropdownlist>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
 
D

Daniel Fisher\(lennybacon\)

Look at

dsGetProducts.Tables("Products")

and

mySqlDataAdapter.Fill(dsGetPRoducts, "products")

see? The dictionary is NOT case insensitive like VB :-(
 
L

Laura K

Thanks. Made all the changes and still doesn't work. I am having this
problem with all nested controls. Don't know why,
 
L

Laura K

Thanks. Made all the changes and still doesn't work. I am having this
problem with all nested controls. Don't know why,
 
C

Christopher Reed

You have dsGetProducts dataset defined in a private Page_Load method. Thus,
the function GetChildData has no access to dsGetProducts. Try using
Protected in place of Private.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top