473,385 Members | 1,472 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.

C# dynamic SQL from Form Input

Dan
I have a date field on a C# form I would like to use in the WHERE
clause of a SQL statement going against Access2002. Do I need to
perform a todate() type funtion on the textbox field on the form? What
would the SQL statement look like?

Thanks in advance - Dan
Nov 15 '05 #1
2 7410
Dan,

You should be using a parameterized query for your SQL statement.
Basically, you would create a SqlCommand (or OleDbCommand, etc, etc), with
the command text of the command like this:

select * from table where datefield = @datefield

Then, you would add the appropriate parameter to the parameters
collection on the command, and set the value of that to a DateTime instance.
When you execute the command, the provider will be responsible for
performing the necessary conversions in the sql statement to a
representation that the database server can understand.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <dl****@amfam.com> wrote in message
news:7e**************************@posting.google.c om...
I have a date field on a C# form I would like to use in the WHERE
clause of a SQL statement going against Access2002. Do I need to
perform a todate() type funtion on the textbox field on the form? What
would the SQL statement look like?

Thanks in advance - Dan

Nov 15 '05 #2
First off, don't use Dynamic Sql, use Parameters ..
http://www.knowdotnet.com/articles/storedprocsvb.html

YOu can use the same methodology that's used here, just set the command
type to text and use ? whereever you want the param to appear

cmd.CommandText = "SELECT * FROM myTable WHERE SOmeDate = ?";

cmd.Parameters.Add(CType(tbMyDateTextBox.text, DateTime))

HTH,

Bill
"Dan" <dl****@amfam.com> wrote in message
news:7e**************************@posting.google.c om...
I have a date field on a C# form I would like to use in the WHERE
clause of a SQL statement going against Access2002. Do I need to
perform a todate() type funtion on the textbox field on the form? What
would the SQL statement look like?

Thanks in advance - Dan

Nov 15 '05 #3

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

Similar topics

11
by: propizzy | last post by:
Appreciate any help!!! PROBLEM: I have this form that allows the user to dynamically create additional fields (see javascript code bellow). I am trying to retrieve the values entered into these...
2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
1
by: SAN CAZIANO | last post by:
I have create a dynamic html table by adding some rows where I have to put some value in an input field and now how can I get all value of all row ??? I try this but it doesn' work button...
4
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see...
0
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.