473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1563
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Drumheller | last post by:
(If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
3
by: Solel Software | last post by:
Hello, I have a basic question. I have a DataTable of information without a database store (it's only in memory). I am looking to somehow query the DataTable to find out which row(s) satisfy...
7
by: Ryan | last post by:
I have a bit of a problem with regards an indexing strategy. Well, basically there is no indexing strategy on a set of data I have at work. Now, I didn't create the design as I would have allowed...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
1
by: macupryk | last post by:
I need to get the value of a datatable. _dtProjectQuestion, ProjectQuestionToDatabase.ProjectResponseandRespondentToDB(_dtProjectQuestion, intId, Convert.ToInt32(var.no)); Error 1 ...
9
by: Pascal Berger | last post by:
What's the fastest way to accomplish the following tasks: - Copy all data from one DataTable to another. Currently I work with CreateDataReader() / Load(). Is there any faster approach? - Add a...
6
by: ArunDhaJ | last post by:
Hi All, I'm having a DataTable with say 3 columns. I've to copy this DataTable to another DataTable which has 4 columns. The extra column is the Row_ID with AutoIncrement property set true. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.