Select method works for String but not DateTime.ToString?

  • Thread starter Vagabond Software
  • Start date
V

Vagabond Software

The problem is that this worked fine on my Windows XP machine, but did not work on any of several Windows 2000 computers at the client's location. The Select method would always return 0 (zero) rows even though we were working with the exact same list of files in both locations.

As part of some experimentation, I changed the Type of the "LastModified" from "System.DateTime" to "System.String" and everything began working as expected at the client's location.

If anyone has any clue as to why I cannot use the "System.DateTime" DataColumn type in the client's Windows 2000 environment when it works perfectly in my Windows XP environment; I would greatly appreciate any input.

Here are the relevant code snippets:

--- DataTable & Column Info ---

this.fileinfo = new DataTable("TestFileInfo");
this.fileinfo.Columns.Add("FileName", Type.GetType("System.String"));
this.fileinfo.Columns.Add("FileSize", Type.GetType("System.UInt64"));
/* DEBUG BEGIN: The following line does not work in client environment...
this.fileinfo.Columns.Add("LastModified", Type.GetType("System.DateTime"));
*/
this.fileinfo.Columns.Add("LastModified", Type.GetType("System.String"));
/* DEBUG END */
this.fileinfo.Columns.Add("FullPath", Type.GetType("System.String"));

--- DataTable Select method Info ---

string exprFile = "FileName LIKE '" + pattern + "*'";
string latestFileDate = dtFiles.Compute("MAX(LastModified)",
exprFile).ToString();

string exprDate = exprFile + " AND LastModified = '" +
latestFileDate + "'";

DataRow[] foundRows = dtFiles.Select(exprDate);
string latestFile = null;
if (foundRows.Length > 0)
latestFile = foundRows[0]["FullPath"].ToString();
return latestFile;

The above code returns 0 (zero) rows if "LastModified" DataColumn type set to System.DateTime.

- carl
 
W

W.G. Ryan eMVP

It could be that the Time Settings format is different on the XP Box than it
is on the 2000 Box. Check the Long Date, Short Date and Time Formats and
see if they are different.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
The problem is that this worked fine on my Windows XP machine, but did not
work on any of several Windows 2000 computers at the client's location. The
Select method would always return 0 (zero) rows even though we were working
with the exact same list of files in both locations.

As part of some experimentation, I changed the Type of the "LastModified"
from "System.DateTime" to "System.String" and everything began working as
expected at the client's location.

If anyone has any clue as to why I cannot use the "System.DateTime"
DataColumn type in the client's Windows 2000 environment when it works
perfectly in my Windows XP environment; I would greatly appreciate any
input.

Here are the relevant code snippets:

--- DataTable & Column Info ---

this.fileinfo = new DataTable("TestFileInfo");
this.fileinfo.Columns.Add("FileName", Type.GetType("System.String"));
this.fileinfo.Columns.Add("FileSize", Type.GetType("System.UInt64"));
/* DEBUG BEGIN: The following line does not work in client environment...
this.fileinfo.Columns.Add("LastModified", Type.GetType("System.DateTime"));
*/
this.fileinfo.Columns.Add("LastModified", Type.GetType("System.String"));
/* DEBUG END */
this.fileinfo.Columns.Add("FullPath", Type.GetType("System.String"));

--- DataTable Select method Info ---

string exprFile = "FileName LIKE '" + pattern + "*'";
string latestFileDate = dtFiles.Compute("MAX(LastModified)",

exprFile).ToString();

string exprDate = exprFile + " AND LastModified = '" +
latestFileDate + "'";

DataRow[] foundRows = dtFiles.Select(exprDate);
string latestFile = null;
if (foundRows.Length > 0)
latestFile = foundRows[0]["FullPath"].ToString();
return latestFile;

The above code returns 0 (zero) rows if "LastModified" DataColumn type set
to System.DateTime.

- carl
 
G

Grzegorz Danowski

U¿ytkownik "Vagabond Software" <[email protected]> napisa³ w
wiadomo¶ci (...)
<cite
string exprFile = "FileName LIKE '" + pattern + "*'";
string latestFileDate = dtFiles.Compute("MAX(LastModified)",
exprFile).ToString();

string exprDate = exprFile + " AND LastModified = '" +
latestFileDate + "'";

DataRow[] foundRows = dtFiles.Select(exprDate);
string latestFile = null;
if (foundRows.Length > 0)
latestFile = foundRows[0]["FullPath"].ToString();
return latestFile;

The above code returns 0 (zero) rows if "LastModified" DataColumn type set
to System.DateTime.
</cite>

Different computers use different data format and therefore you must use
common (american) format.
Please try so method:

public static string DateToSelect(DateTime dtIn)
{
return dtIn.ToString("#MM\\/dd\\/yyyy hh:mm#");
}

And later:

string exprFile = "FileName LIKE '" + pattern + "*'";
string latestFileDate = DateToSelect(dtFiles.Compute("MAX(LastModified)",
exprFile))

(...)

I hope that it helps.
Regards,
Grzegorz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top