473,396 Members | 1,998 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,396 software developers and data experts.

SQL concatenating in C#

2
Hello,
I have a table in a data base named Table (access data base), with the following fields:
Name - string
TheaterNr - number
Day - date/time

and i`m trying to store in an OleDbCommand X.Command an sql statement:

X.Command = "SELECT Name, TheaterNr, Day FROM Table WHERE Name = <name of a variable that stores a string> AND TheaterNr = <name of a variable that stores a number> AND Day = <name of a variable that stores a date/time>"

I`m lost among all the ' " and i don`t know how to use the CAST function as i think it`s necessary for the parsing of the number and date/time variables.
I hope you can help me :)
Apr 30 '11 #1
3 3616
Here's an example of an SQL string that i've concatenated in my program.

Expand|Select|Wrap|Line Numbers
  1. "SELECT code, moduletitle, body, timeofday, duration, examdate FROM EXAMDAT WHERE examdate BETWEEN #01/05/2011# AND #09/04/2022# AND body='OCR';"
As you can see at the WHERE statement, I have used sinle quotes around the string I want to look for.

Expand|Select|Wrap|Line Numbers
  1. "SELECT code, moduletitle, body, timeofday, duration, examdate FROM EXAMDAT WHERE examdate BETWEEN #" + fromDate + "# AND #" + toDate + "# AND body='OCR';";
And here's what the string was made from
May 1 '11 #2
adriancs
122 100+
try this:
Expand|Select|Wrap|Line Numbers
  1. string name = "John";
  2. int theaterno = 1;
  3. string date = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
  4. X.Command = string.Format("SELECT Name, TheaterNr, Day FROM Table WHERE Name = '{0}' AND TheaterNr = '{1}' AND Day = '{2}'",name, theaterno, date);
May 1 '11 #3
Radu
2
Thank you. Your answers helped and i`ve figuered it out eventualy.
May 3 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dont bother | last post by:
Hey, I have these attributes: index which is a numerical value value vector which is a numerical float value and I want to concatenate like this:
14
by: foodic | last post by:
i am fresher to C++ programming, and I just want to learn Concatenating Calls, I have written a program, class SetMe { public: void setX(int x) {_x = x;} void setY(int y) {_y = y;} void...
6
by: nwheavyw8 | last post by:
I am currently trying to write a simple PHP script that will split an uploading file up into 500kb "chunks", then read and concatenate them back together when accessed for download. I can't seem...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
4
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I can´t see...
1
by: ebobnar | last post by:
I need to call the function LoadImage which take a LPCTSTR argument to specify the path to the image to load. However, I need to create this path dynamically from user input by concatenating...
4
by: FB's .NET Dev PC | last post by:
Interesting note, the code below as is will attempt to cast what is clearly indicated as a string into a double. This is becuase the use of + as a concatenation operator. The error message...
0
by: bob brar | last post by:
hi, I have the following function in a class. Public Function getCustomers() As DataSet Dim Db As New CDatabaseAccessor getCustomers = Db.getData("SELECT A.*, RTRIM( A.TITLE)+', '+ RTRIM...
4
by: Richard L Rosenheim | last post by:
Is there any built-in method or mechanism for concatenating two arrays of byte together? I haven't come across anything to do this, and was just checking before I implement some code. Richard...
7
by: Mary | last post by:
I have a student who has a hyphenated first name. If I concatenate the name like this: StudentName:( & ", " & ), it works as expected. If, however, I try to get the first name first by...
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
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.