Date Query within C# to Access 2002

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have a form in C# that I have a textBox1.Text with a value of
"12/01/03". How do I write the SQL to use this field at runtime? I
have an oleDbdataadaptor set up that looks like this:

SELECT ID, [Date], [Adj Close*]
FROM NDXDailyImport
WHERE ([Date] = #12/01/2003#)

which works fine...obviously not pulling in the text field. Help
appreciated...

Thanks in advance - Dan
 
Hi Dan,

As a simplest solution you could concatenate sql command.
Something like:
commandtext = "SELECT ID, [Date], [Adj Close*] FROM
NDXDailyImport WHERE ([Date] = #" + textBox1.Text + "#)"

However, this method is not recommended at all and is prone to attacks.
The right way would be to use parametrised command.
 
Miha,

Could you point me to a parameterized command for Access
2002?
Thanks in advance - Dan
-----Original Message-----
Hi Dan,

As a simplest solution you could concatenate sql command.
Something like:
commandtext = "SELECT ID, [Date], [Adj Close*] FROM
NDXDailyImport WHERE ([Date] = #" + textBox1.Text + "#)"

However, this method is not recommended at all and is prone to attacks.
The right way would be to use parametrised command.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dan said:
I have a form in C# that I have a textBox1.Text with a value of
"12/01/03". How do I write the SQL to use this field at runtime? I
have an oleDbdataadaptor set up that looks like this:

SELECT ID, [Date], [Adj Close*]
FROM NDXDailyImport
WHERE ([Date] = #12/01/2003#)

which works fine...obviously not pulling in the text field. Help
appreciated...

Thanks in advance - Dan


.
 
Hi Dan,

I was going to, but I didn't know the database you are using :)
Here it is:
this.oleDbSelectCommand1.CommandText = "SELECT ID, [Date], [Adj Close*] FROM
NDXDailyImport WHERE [Date]= ?";

this.oleDbSelectCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Date", System.Data.OleDb.OleDbType.Date));



Make sure you set oleDbSelectCommand1.Parameters["Date"].Value to date prior
to doing select.


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dan said:
Miha,

Could you point me to a parameterized command for Access
2002?
Thanks in advance - Dan
-----Original Message-----
Hi Dan,

As a simplest solution you could concatenate sql command.
Something like:
commandtext = "SELECT ID, [Date], [Adj Close*] FROM
NDXDailyImport WHERE ([Date] = #" + textBox1.Text + "#)"

However, this method is not recommended at all and is prone to attacks.
The right way would be to use parametrised command.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dan said:
I have a form in C# that I have a textBox1.Text with a value of
"12/01/03". How do I write the SQL to use this field at runtime? I
have an oleDbdataadaptor set up that looks like this:

SELECT ID, [Date], [Adj Close*]
FROM NDXDailyImport
WHERE ([Date] = #12/01/2003#)

which works fine...obviously not pulling in the text field. Help
appreciated...

Thanks in advance - Dan


.
 
Back
Top