469,649 Members | 1,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Datatable indexing problem

I am having a problem with a Datatable access.

This statement apparently works fine:

response.write(GetRows.Rows(ktr)(1))

and this statement does not:

if e.day.date = GetRows(ktr)(1) then

Here is the snippet of code that has these statements
************************************************** ********************
Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
Dim totalRows as integer
Dim totalColumns as Integer

totalRows = GetRows.Rows.Count
totalColumns = GetRows.Columns.count
response.write("Rows read again = " & totalRows & " columns = " &
totalColumns & "<br>")

for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if CDate(e.day.date) = _
CDate(GetRows(ktr)(1)) then
************************************************** **************************
*******

Here is the error I get.
************************************************** **************************
************
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if CDate(e.day.date) = _
Line 126: CDate(GetRows(ktr)(1)) then
Line 127: response.write("Dates equal")
Line 128: else
************************************************** **************************
*

Why cannot the GetRows Datatable not be indexed in the if statement, but it
works fine in the response.write?

Thanks,

Tom.
Nov 18 '05 #1
5 1409
Rows collection has no indexes by name - only by index
so if you want to get the value from the first row whitin the ktr column you
have to write

GetRows.Rows(1)(ktr)
Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
I am having a problem with a Datatable access.

This statement apparently works fine:

response.write(GetRows.Rows(ktr)(1))

and this statement does not:

if e.day.date = GetRows(ktr)(1) then

Here is the snippet of code that has these statements
************************************************** ********************
Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
Dim totalRows as integer
Dim totalColumns as Integer

totalRows = GetRows.Rows.Count
totalColumns = GetRows.Columns.count
response.write("Rows read again = " & totalRows & " columns = " &
totalColumns & "<br>")

for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if CDate(e.day.date) = _
CDate(GetRows(ktr)(1)) then
************************************************** ************************** *******

Here is the error I get.
************************************************** ************************** ************
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if CDate(e.day.date) = _
Line 126: CDate(GetRows(ktr)(1)) then
Line 127: response.write("Dates equal")
Line 128: else
************************************************** ************************** *

Why cannot the GetRows Datatable not be indexed in the if statement, but it works fine in the response.write?

Thanks,

Tom.

Nov 18 '05 #2
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
Rows collection has no indexes by name - only by index
so if you want to get the value from the first row whitin the ktr column you have to write

GetRows.Rows(1)(ktr)
Actually, it is the other way around. The row is the number that is
changing. Column 1 is a date I was trying to get out of the table which
happens to be in the 2nd column (starting at 0).

ktr is going to be equal to 0 and 1 (as there are 2 rows in the table at the
moment). Totalrows is = 2.

What I am confused is why the response.write line works and the if test does
not.

Tom.

Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
I am having a problem with a Datatable access.

This statement apparently works fine:

response.write(GetRows.Rows(ktr)(1))

and this statement does not:

if e.day.date = GetRows(ktr)(1) then

Here is the snippet of code that has these statements
************************************************** ********************
Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
Dim totalRows as integer
Dim totalColumns as Integer

totalRows = GetRows.Rows.Count
totalColumns = GetRows.Columns.count
response.write("Rows read again = " & totalRows & " columns = " &
totalColumns & "<br>")

for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if CDate(e.day.date) = _
CDate(GetRows(ktr)(1)) then

************************************************** **************************
*******

Here is the error I get.

************************************************** **************************
************
Compilation Error
Description: An error occurred during the compilation of a resource

required
to service this request. Please review the following specific error

details
and modify your source code appropriately.

Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if CDate(e.day.date) = _
Line 126: CDate(GetRows(ktr)(1)) then
Line 127: response.write("Dates equal")
Line 128: else

************************************************** **************************
*

Why cannot the GetRows Datatable not be indexed in the if statement, but

it
works fine in the response.write?

Thanks,

Tom.


Nov 18 '05 #3
It is may be because DataTable.Rows(RowIndex)(ColumnIndex) return object and
you have to convert it to datatime object like

if Not GetRows(ktr)(1) = Nothing Then
if e.day.date = DateTime.Parse(GetRows(ktr)(1).ToString()) then

Hope This Helps
Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
Rows collection has no indexes by name - only by index
so if you want to get the value from the first row whitin the ktr column you
have to write

GetRows.Rows(1)(ktr)


Actually, it is the other way around. The row is the number that is
changing. Column 1 is a date I was trying to get out of the table which
happens to be in the 2nd column (starting at 0).

ktr is going to be equal to 0 and 1 (as there are 2 rows in the table at

the moment). Totalrows is = 2.

What I am confused is why the response.write line works and the if test does not.

Tom.


Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
I am having a problem with a Datatable access.

This statement apparently works fine:

response.write(GetRows.Rows(ktr)(1))

and this statement does not:

if e.day.date = GetRows(ktr)(1) then

Here is the snippet of code that has these statements
************************************************** ********************
Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
Dim totalRows as integer
Dim totalColumns as Integer

totalRows = GetRows.Rows.Count
totalColumns = GetRows.Columns.count
response.write("Rows read again = " & totalRows & " columns = " &
totalColumns & "<br>")

for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if CDate(e.day.date) = _
CDate(GetRows(ktr)(1)) then

************************************************** **************************
*******

Here is the error I get.

************************************************** **************************
************
Compilation Error
Description: An error occurred during the compilation of a resource

required
to service this request. Please review the following specific error

details
and modify your source code appropriately.

Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if CDate(e.day.date) = _
Line 126: CDate(GetRows(ktr)(1)) then
Line 127: response.write("Dates equal")
Line 128: else

************************************************** **************************
*

Why cannot the GetRows Datatable not be indexed in the if statement,
but it
works fine in the response.write?

Thanks,

Tom.



Nov 18 '05 #4
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl...
It is may be because DataTable.Rows(RowIndex)(ColumnIndex) return object and you have to convert it to datatime object like

if Not GetRows(ktr)(1) = Nothing Then
if e.day.date = DateTime.Parse(GetRows(ktr)(1).ToString()) then
Tried it. Still doesn't work.

Here is the result and the new code:

************************************************** ***********************
Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if e.day.date = _
Line 126: DateTime.Parse(GetRows(ktr)(1).ToString) then
Line 127: response.write("Dates equal")
Line 128: else
Source File: c:\inetpub\wwwroot\contour\Company Info\TMP1lpu3zq39q.aspx
Line: 126
************************************************** **************************
****
for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if e.day.date = _
DateTime.Parse(GetRows(ktr)(1).ToString) then
response.write("Dates equal")
else
response.write("dates not equal")
end if
next
************************************************** **************************
*

It is interesting that the response.write works but the compare does not.

Tom
Hope This Helps
Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
Rows collection has no indexes by name - only by index
so if you want to get the value from the first row whitin the ktr column
you
have to write

GetRows.Rows(1)(ktr)
Actually, it is the other way around. The row is the number that is
changing. Column 1 is a date I was trying to get out of the table which
happens to be in the 2nd column (starting at 0).

ktr is going to be equal to 0 and 1 (as there are 2 rows in the table at

the
moment). Totalrows is = 2.

What I am confused is why the response.write line works and the if test

does
not.

Tom.


Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
> I am having a problem with a Datatable access.
>
> This statement apparently works fine:
>
> response.write(GetRows.Rows(ktr)(1))
>
> and this statement does not:
>
> if e.day.date = GetRows(ktr)(1) then
>
> Here is the snippet of code that has these statements
>
************************************************** ******************** > Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
> Dim totalRows as integer
> Dim totalColumns as Integer
>
> totalRows = GetRows.Rows.Count
> totalColumns = GetRows.Columns.count
> response.write("Rows read again = " & totalRows & " columns = " &
> totalColumns & "<br>")
>
> for ktr = 0 to GetRows.Rows.Count - 1
> response.write(GetRows.Rows(ktr)(1))
> response.write( e.day.date)
> if CDate(e.day.date) = _
> CDate(GetRows(ktr)(1)) then
>

************************************************** **************************
> *******
>
> Here is the error I get.
>

************************************************** **************************
> ************
> Compilation Error
> Description: An error occurred during the compilation of a resource
required
> to service this request. Please review the following specific error
details
> and modify your source code appropriately.
>
> Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
> indexed because it has no default property.
>
> Source Error:
>
> Line 124: response.write( e.day.date)
> Line 125: if CDate(e.day.date) = _
> Line 126: CDate(GetRows(ktr)(1)) then
> Line 127: response.write("Dates equal")
> Line 128: else
>

************************************************** ************************** > *
>
> Why cannot the GetRows Datatable not be indexed in the if statement, but it
> works fine in the response.write?
>
> Thanks,
>
> Tom.
>
>



Nov 18 '05 #5
Hi Thomas,

Please excuse me but i was in hurry and missed something
this line
DateTime.Parse(GetRows(ktr)(1).ToString) then
should be
DateTime.Parse(GetRows.Rows(ktr)(1).ToString) then

as you can see i've missed the Rows collection that need to be indexed

Regards
Martin
"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl...
It is may be because DataTable.Rows(RowIndex)(ColumnIndex) return object and
you have to convert it to datatime object like

if Not GetRows(ktr)(1) = Nothing Then
if e.day.date = DateTime.Parse(GetRows(ktr)(1).ToString()) then


Tried it. Still doesn't work.

Here is the result and the new code:

************************************************** ***********************
Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot be
indexed because it has no default property.

Source Error:

Line 124: response.write( e.day.date)
Line 125: if e.day.date = _
Line 126: DateTime.Parse(GetRows(ktr)(1).ToString) then
Line 127: response.write("Dates equal")
Line 128: else
Source File: c:\inetpub\wwwroot\contour\Company Info\TMP1lpu3zq39q.aspx
Line: 126

************************************************** ************************** ****
for ktr = 0 to GetRows.Rows.Count - 1
response.write(GetRows.Rows(ktr)(1))
response.write( e.day.date)
if e.day.date = _
DateTime.Parse(GetRows(ktr)(1).ToString) then
response.write("Dates equal")
else
response.write("dates not equal")
end if
next
************************************************** ************************** *

It is interesting that the response.write works but the compare does not.

Tom

Hope This Helps
Regards
Martin

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
> Rows collection has no indexes by name - only by index
> so if you want to get the value from the first row whitin the ktr column you
> have to write
>
> GetRows.Rows(1)(ktr)

Actually, it is the other way around. The row is the number that is
changing. Column 1 is a date I was trying to get out of the table which happens to be in the 2nd column (starting at 0).

ktr is going to be equal to 0 and 1 (as there are 2 rows in the table at
the
moment). Totalrows is = 2.

What I am confused is why the response.write line works and the if
test
does
not.

Tom.
>
>
> Regards
> Martin
>
> "Thomas Scheiderich" <tf*@deltanet.com> wrote in message
> news:10*************@corp.supernews.com...
> > I am having a problem with a Datatable access.
> >
> > This statement apparently works fine:
> >
> > response.write(GetRows.Rows(ktr)(1))
> >
> > and this statement does not:
> >
> > if e.day.date = GetRows(ktr)(1) then
> >
> > Here is the snippet of code that has these statements
> > ************************************************** ******************** > > Dim GetRows as DataTable = sqlDS.tables("eventCalendar")
> > Dim totalRows as integer
> > Dim totalColumns as Integer
> >
> > totalRows = GetRows.Rows.Count
> > totalColumns = GetRows.Columns.count
> > response.write("Rows read again = " & totalRows & " columns = "
& > > totalColumns & "<br>")
> >
> > for ktr = 0 to GetRows.Rows.Count - 1
> > response.write(GetRows.Rows(ktr)(1))
> > response.write( e.day.date)
> > if CDate(e.day.date) = _
> > CDate(GetRows(ktr)(1)) then
> >
>

************************************************** **************************
> > *******
> >
> > Here is the error I get.
> >
>

************************************************** **************************
> > ************
> > Compilation Error
> > Description: An error occurred during the compilation of a resource > required
> > to service this request. Please review the following specific error > details
> > and modify your source code appropriately.
> >
> > Compiler Error Message: BC30367: Class 'System.Data.DataTable' cannot
be
> > indexed because it has no default property.
> >
> > Source Error:
> >
> > Line 124: response.write( e.day.date)
> > Line 125: if CDate(e.day.date) = _
> > Line 126: CDate(GetRows(ktr)(1)) then
> > Line 127: response.write("Dates equal")
> > Line 128: else
> >
>

************************************************** **************************
> > *
> >
> > Why cannot the GetRows Datatable not be indexed in the if

statement, but
> it
> > works fine in the response.write?
> >
> > Thanks,
> >
> > Tom.
> >
> >
>
>



Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Michael Drumheller | last post: by
108 posts views Thread by Bryan Olson | last post: by
3 posts views Thread by Solel Software | last post: by
7 posts views Thread by Ryan | last post: by
9 posts views Thread by Pascal Berger | last post: by
6 posts views Thread by ArunDhaJ | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.