N
Nathan Sokalski
I am attempting to access a DataKey that has more than one value. The code I
use to create the table and where the error occurs are:
Creating the DataTable:
cart.Columns.Add(New DataColumn("productid", GetType(Integer)))
cart.Columns.Add(New DataColumn("producttable", GetType(Integer)))
cart.Columns.Add(New DataColumn("quantity", GetType(Integer)))
cart.Columns.Add(New DataColumn("price", GetType(Single)))
Dim x() As DataColumn = {cart.Columns(0), cart.Columns(1)}
cart.PrimaryKey = x
Where the error occurs:
Private Sub AddToCart(ByVal productid As Integer)
Dim x() As Integer = {productid, Me.categoryid}
If Me.cart.Rows.Contains(x) Then
When I run my code, I recieve the following error message:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Expecting 2 value(s) for the key being indexed, but received 1 value(s).
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.ArgumentException: Expecting 2 value(s) for the
key being indexed, but received 1 value(s).
Source Error:
Line 46: Private Sub AddToCart(ByVal productid As Integer)
Line 47: Dim x() As Integer = {productid, Me.categoryid}
Line 48: If Me.cart.Rows.Contains(x) Then
Line 49:
Me.cart.Rows(Me.cart.Rows.IndexOf(Me.cart.Rows.Find(x)))(2) =
CInt(Me.cart.Rows(Me.cart.Rows.IndexOf(Me.cart.Rows.Find(x)))(2)) + 1
Line 50: Else
The error occurs on line 48 (in the Contains() method). The error says that
it is expecting 2 values, but you will notice that on line 47 I declare x()
and initialize it to an array of 2 values, and then use it as the parameter
for Contains() in line 48. What am I doing wrong? Thanks.
use to create the table and where the error occurs are:
Creating the DataTable:
cart.Columns.Add(New DataColumn("productid", GetType(Integer)))
cart.Columns.Add(New DataColumn("producttable", GetType(Integer)))
cart.Columns.Add(New DataColumn("quantity", GetType(Integer)))
cart.Columns.Add(New DataColumn("price", GetType(Single)))
Dim x() As DataColumn = {cart.Columns(0), cart.Columns(1)}
cart.PrimaryKey = x
Where the error occurs:
Private Sub AddToCart(ByVal productid As Integer)
Dim x() As Integer = {productid, Me.categoryid}
If Me.cart.Rows.Contains(x) Then
When I run my code, I recieve the following error message:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Expecting 2 value(s) for the key being indexed, but received 1 value(s).
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.ArgumentException: Expecting 2 value(s) for the
key being indexed, but received 1 value(s).
Source Error:
Line 46: Private Sub AddToCart(ByVal productid As Integer)
Line 47: Dim x() As Integer = {productid, Me.categoryid}
Line 48: If Me.cart.Rows.Contains(x) Then
Line 49:
Me.cart.Rows(Me.cart.Rows.IndexOf(Me.cart.Rows.Find(x)))(2) =
CInt(Me.cart.Rows(Me.cart.Rows.IndexOf(Me.cart.Rows.Find(x)))(2)) + 1
Line 50: Else
The error occurs on line 48 (in the Contains() method). The error says that
it is expecting 2 values, but you will notice that on line 47 I declare x()
and initialize it to an array of 2 values, and then use it as the parameter
for Contains() in line 48. What am I doing wrong? Thanks.