473,669 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable, Contains method

Hi

I'm trying to call the method Contains in a loop: out of the loop I set the
primary key of the dataTable.

The method returns true one time at a certani value, but then, when the loop
steps forward to check another value, the method returns false, although the
value is contained in the dataTable (DateTime values). So the loop goes and
goes ...

Also tried with Find, but I had the same result.

Can anyone help me?

Marco
Nov 16 '05 #1
6 17431
Hi,

Can you post the code in question?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Millo" <mi************ **@libero.it> wrote in message
news:Gi******** *************@t wister2.libero. it...
Hi

I'm trying to call the method Contains in a loop: out of the loop I set the primary key of the dataTable.

The method returns true one time at a certani value, but then, when the loop steps forward to check another value, the method returns false, although the value is contained in the dataTable (DateTime values). So the loop goes and goes ...

Also tried with Find, but I had the same result.

Can anyone help me?

Marco

Nov 16 '05 #2
Millo <mi************ **@libero.it> wrote:
I'm trying to call the method Contains in a loop: out of the loop I set the
primary key of the dataTable.

The method returns true one time at a certani value, but then, when the loop
steps forward to check another value, the method returns false, although the
value is contained in the dataTable (DateTime values). So the loop goes and
goes ...

Also tried with Find, but I had the same result.

Can anyone help me?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
[...]

private void setPrimaryKeys( ) // in order to use the Contains method of the
dataTable
{
DataColumn[] columnPrimaryKe ys = new DataColumn[1];
columnPrimaryKe ys[0] = this.Columns["date"];
this.PrimaryKey = columnPrimaryKe ys;
}

public bool HasDate( DateTime date )
{
bool hasDate;
hasDate = this.Rows.Conta ins(date);
return hasDate;
}

public DateTime GetQuoteDateOrP receding( DateTime date )
{
if(this.HasDate (date))
{
return date;
}
else
{
return GetQuoteDateOrP receding(date.S ubtract(new
TimeSpan(1,0,0, 0)));
}
}
the problem is in the HasDate method: it works just one time: then
GetQuoteDateOrP receding continues without returning a date because the
hasDate method fails to return true (although I see with my eyes - with the
VS debugger - that the dates passed as parameters ARE in the dataTable in
the column "date").
It seems to me very absurd ... I can't understand where I'm wrong (I've been
debugging for hours, but nothing.)

Thanks in advance.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> ha scritto nel messaggio
news:MP******** *************** *@msnews.micros oft.com...
Millo <mi************ **@libero.it> wrote:
I'm trying to call the method Contains in a loop: out of the loop I set the primary key of the dataTable.

The method returns true one time at a certani value, but then, when the loop steps forward to check another value, the method returns false, although the value is contained in the dataTable (DateTime values). So the loop goes and goes ...

Also tried with Find, but I had the same result.

Can anyone help me?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
Millo,
Remember that a DateTime in .NET has both Date & Time information in it.

Are you certain that the DateTime you pass to HasDate only has a date in it
and the DateTimes in your datatables only have dates in them?

In other words, you don't have time floating around in any of your DateTime
objects? As Time (specifically fractions of milliseconds) would make
matching significantly more difficult...
I would probably add -1 days to the date instead
return GetQuoteDateOrP receding(date.S ubtract(new
TimeSpan(1,0,0, 0)));
return GetQuoteDateOrP receding(date.A ddDays(-1));

Hope this helps
Jay
"Millo" <mi************ **@libero.it> wrote in message
news:ss******** *************@t wister1.libero. it... [...]

private void setPrimaryKeys( ) // in order to use the Contains method of the dataTable
{
DataColumn[] columnPrimaryKe ys = new DataColumn[1];
columnPrimaryKe ys[0] = this.Columns["date"];
this.PrimaryKey = columnPrimaryKe ys;
}

public bool HasDate( DateTime date )
{
bool hasDate;
hasDate = this.Rows.Conta ins(date);
return hasDate;
}

public DateTime GetQuoteDateOrP receding( DateTime date )
{
if(this.HasDate (date))
{
return date;
}
else
{
return GetQuoteDateOrP receding(date.S ubtract(new
TimeSpan(1,0,0, 0)));
}
}
the problem is in the HasDate method: it works just one time: then
GetQuoteDateOrP receding continues without returning a date because the
hasDate method fails to return true (although I see with my eyes - with the VS debugger - that the dates passed as parameters ARE in the dataTable in
the column "date").
It seems to me very absurd ... I can't understand where I'm wrong (I've been debugging for hours, but nothing.)

Thanks in advance.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> ha scritto nel messaggio
news:MP******** *************** *@msnews.micros oft.com...
Millo <mi************ **@libero.it> wrote:
I'm trying to call the method Contains in a loop: out of the loop I
set
the primary key of the dataTable.

The method returns true one time at a certani value, but then, when
the
loop steps forward to check another value, the method returns false,
although
the value is contained in the dataTable (DateTime values). So the loop
goes
and goes ...

Also tried with Find, but I had the same result.

Can anyone help me?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #5
Millo <mi************ **@libero.it> wrote:
[...]

private void setPrimaryKeys( ) // in order to use the Contains method of the
dataTable


This isn't a complete program. Please read the link I posted before.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Jay,
thank you for your tips.

In my DataTable I had only dates: but not in the parameters I passed to the
HasDate(date) method.
using: <<this.Rows.Con tains(date.Date )>> and not simply
<<this.Rows.Con tains(date)>> in this method, I made it work properly.
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> ha scritto nel
messaggio news:e6******** ******@TK2MSFTN GP11.phx.gbl...
Millo,
Remember that a DateTime in .NET has both Date & Time information in it.

Are you certain that the DateTime you pass to HasDate only has a date in it and the DateTimes in your datatables only have dates in them?

In other words, you don't have time floating around in any of your DateTime objects? As Time (specifically fractions of milliseconds) would make
matching significantly more difficult...
I would probably add -1 days to the date instead
return GetQuoteDateOrP receding(date.S ubtract(new
TimeSpan(1,0,0, 0)));


return GetQuoteDateOrP receding(date.A ddDays(-1));

Hope this helps
Jay
"Millo" <mi************ **@libero.it> wrote in message
news:ss******** *************@t wister1.libero. it...
[...]

private void setPrimaryKeys( ) // in order to use the Contains method of

the
dataTable
{
DataColumn[] columnPrimaryKe ys = new DataColumn[1];
columnPrimaryKe ys[0] = this.Columns["date"];
this.PrimaryKey = columnPrimaryKe ys;
}

public bool HasDate( DateTime date )
{
bool hasDate;
hasDate = this.Rows.Conta ins(date);
return hasDate;
}

public DateTime GetQuoteDateOrP receding( DateTime date )
{
if(this.HasDate (date))
{
return date;
}
else
{
return GetQuoteDateOrP receding(date.S ubtract(new
TimeSpan(1,0,0, 0)));
}
}
the problem is in the HasDate method: it works just one time: then
GetQuoteDateOrP receding continues without returning a date because the
hasDate method fails to return true (although I see with my eyes - with

the
VS debugger - that the dates passed as parameters ARE in the dataTable in the column "date").
It seems to me very absurd ... I can't understand where I'm wrong (I've

been
debugging for hours, but nothing.)

Thanks in advance.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> ha scritto nel messaggio
news:MP******** *************** *@msnews.micros oft.com...
Millo <mi************ **@libero.it> wrote:
> I'm trying to call the method Contains in a loop: out of the loop I

set
the
> primary key of the dataTable.
>
> The method returns true one time at a certani value, but then, when

the
loop
> steps forward to check another value, the method returns false,

although
the
> value is contained in the dataTable (DateTime values). So the loop

goes
and
> goes ...
>
> Also tried with Find, but I had the same result.
>
> Can anyone help me?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too





Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8214
by: gabyluna | last post by:
Hi, I´m trying to use the Select method for the DataTable objects of the System.Data library. The problem is that when the datatype of the object that's being searched is an string, I get the correct DataRows from the DataTable, but if the datatype is an integer or a decimal, then I get nothing... Here´s part of the code
6
1753
by: Mountain Bikn' Guy | last post by:
When one gets a row from a database (ie, a DataTable), the row contains a typed value in each column. How is this typically implemented behind scenes. I want to build this functionality myself. The reason I want to do this is because I need an in-memory table without any of the overhead of a DataSet or DataTable. Thanks!
2
316
by: | last post by:
Hello all I have a dataset which contains 3 datatables. I traverse each datatable and check the rows. I should be able to get values out of these datatables and create a new datatable? Is this possible? or does a datatable always have to be associated with a SQL query or a SQL table? Thanks and I appreciate your help very much.
3
8077
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one statement to VB.NET and this is crucial: re-implementing ISerializable.GetObjectData() in the DataTable derived class so serializing the datatable derived class will call this method and not the DataTable version (which is private, so overriding is also...
4
11159
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and call the following method. public void JobListDataTableFromAccessCommitChange() { System.Data.DataTable oChangeDataTable;
4
10215
by: Joseph Geretz | last post by:
I don't get it. A DataTable can't be returned, but a DataSet can. Yet a DataSet contains one or more DataTables. So obviously a DataTable must be serializable. So why not just let me return a DataTable? Thanks for your advice, - Joe Geretz -
5
8635
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
4
4128
by: ArunDhaJ | last post by:
Hi, I've to filter rows from DataTable Select There is a column named "Phone" which contains values in the following format: (901) 789 1234<BR>(901) 789 1235<BR>(901) 789 1221 I need to filter based on the phone number. the search criteria could be 9017891221 or 891221. this string should filter the above column
0
860
by: Craig Buchanan | last post by:
I would like to override the DataTable.Rows.Contains() method to encapsulate the DataTable's DefaultView's FindRows() method. It would be nice to be able to test an array of alternate keys in addition to the primary key. Questions: * I'm assuming that I can do this in the XSD file's Designer.vb file. Is this the best location for this? * I've noticed that changes to the DataTable's Select commandText seems to re-created the Designer...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7405
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.