L
Laura K
I have been trying to figure this one out. I really need help. I have
a relationship between two tables - product and colors. I have a
repeater listing the products and then each product has a drop down
with the corresponding colors. However when I try to view the page I
get:
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 70:
Line 71:
Line 72: DropDownList1.DataSource =
dsGetProducts.Tables("colors")
Line 73: DropDownList1.DataBind()
Line 74:
Here is the code The error is near the bottom of the code. It is
basically stating that the dropdown datasource is not set to an
instance of an object. HELP!
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strProductCode = Request.QueryString("ProductCode")
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")
dsGetProducts.Tables(0).TableName = "Products"
dsGetProducts.Tables(1).TableName = "Colors"
dsGetProducts.Relations.Add("ProductsToColors",
dsGetProducts.Tables("products").Columns("intProductID"),
dsGetProducts.Tables("colors").Columns("intProductID"), False)
DropDownList1.DataSource = dsGetProducts.Tables("colors")
DropDownList1.DataBind()
Repeater1.DataSource = dsGetProducts.Tables("products")
Repeater1.DataBind()
End Sub
Any help is appreciated.
Laura K
a relationship between two tables - product and colors. I have a
repeater listing the products and then each product has a drop down
with the corresponding colors. However when I try to view the page I
get:
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 70:
Line 71:
Line 72: DropDownList1.DataSource =
dsGetProducts.Tables("colors")
Line 73: DropDownList1.DataBind()
Line 74:
Here is the code The error is near the bottom of the code. It is
basically stating that the dropdown datasource is not set to an
instance of an object. HELP!
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strProductCode = Request.QueryString("ProductCode")
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")
dsGetProducts.Tables(0).TableName = "Products"
dsGetProducts.Tables(1).TableName = "Colors"
dsGetProducts.Relations.Add("ProductsToColors",
dsGetProducts.Tables("products").Columns("intProductID"),
dsGetProducts.Tables("colors").Columns("intProductID"), False)
DropDownList1.DataSource = dsGetProducts.Tables("colors")
DropDownList1.DataBind()
Repeater1.DataSource = dsGetProducts.Tables("products")
Repeater1.DataBind()
End Sub
Any help is appreciated.
Laura K