Re: Select statement for boolean and/or DateTime values?




"Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx> wrote in message news:uRfU%23XwEIHA.4028@xxxxxxxxxxxxxxxxxxxxxxx
Olaf Krause wrote:
Hi together,
....
microsoft.public.dotnet.framework.adonet.

Oops you're right, did not pay enough attention on the net behind the ado



It does?? SQL Server does not have a boolean datatype, and even if it did, you cannot compare a boolean with a string?? Are you sure "booleancolumn" isn't actually a varchar column?

yepp it works, and the column is boolean or to be more precise bit. I doublechecked this using directly the SQLQuery tool within the SQL Server Management Studio.

The closest SQL Server has to a boolean
datatype is the bit datatype, which holds 0,1 or Null. If you utilize parameters, ADO.Net will translate a boolean value into either 0 or 1.
You should also use a standard datetime format, such as ISO: yyyymmdd hh:nn:ss will always work, at least in SQL Server. But again, utilizing parameters will relieve you of the necessity of worrying about date formats.

OK, currently I'm rewriting my code to use parameters instead of directly setting the values as strings.

. But for the rest the select statement seems not to work
as expected.

Access (Jet) DOES have a boolean datatype, but, it requires a nonstandard date format: either US (mm/dd/yyyy) or tyyyy-mm-dd.

You are right, that's what I also found out

Again, if you utilize parameters, values will be passed correctly to the Jet engine
....

No, there will be differences in SQL dialectst depending on the database. However, utilizing parameters will help.

==>

I think something like
string command= "SELECT * FROM mytable WHERE datetimecolumn= @datetimecolumn";
IDbCommand cmd=AdoProviderFactory.GetCommand(command,m_DB.Connection,m_DB.ProviderType);
cmd.Parameters.Add(new xyzDbParameter("@datetimecolumn", xyzDbType.Date)).Value = New DateTime("20.10.2007 10:43:25")