473,405 Members | 2,310 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,405 software developers and data experts.

string literal with sql

Hi, why is the @ not doing it's job here?

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
["Product"],
Sum(InvoiceLine.InvoiceLineQuantity) AS ["Quantity"] FROM Invoice,
InvoiceLine
WHERE (((Invoice.TxnID)=[InvoiceLine].[TxnID])
AND ((InvoiceLine.InvoiceLineItemRefFullName)>'')
AND ((InvoiceLine.InvoiceLineQuantity)>0)
AND ((Invoice.TimeCreated)>#1/1/2004 11:20:6#
And (Invoice.TimeCreated)<#3/1/2004 11:20:6#))
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";
Nov 16 '05 #1
8 5511
Jimbo <bl**@example.com> wrote:
Hi, why is the @ not doing it's job here?

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
["Product"],
Sum(InvoiceLine.InvoiceLineQuantity) AS ["Quantity"] FROM Invoice,
InvoiceLine
WHERE (((Invoice.TxnID)=[InvoiceLine].[TxnID])
AND ((InvoiceLine.InvoiceLineItemRefFullName)>'')
AND ((InvoiceLine.InvoiceLineQuantity)>0)
AND ((Invoice.TimeCreated)>#1/1/2004 11:20:6#
And (Invoice.TimeCreated)<#3/1/2004 11:20:6#))
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";


What do you think it ought to be doing which it's not? You need to
double up on " when using verbatim string literals though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
On Fri, 7 May 2004 15:38:07 +0100, Jon Skeet [C# MVP] wrote:
Jimbo <bl**@example.com> wrote:
Hi, why is the @ not doing it's job here?

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
["Product"],
Sum(InvoiceLine.InvoiceLineQuantity) AS ["Quantity"] FROM Invoice,
InvoiceLine
WHERE (((Invoice.TxnID)=[InvoiceLine].[TxnID])
AND ((InvoiceLine.InvoiceLineItemRefFullName)>'')
AND ((InvoiceLine.InvoiceLineQuantity)>0)
AND ((Invoice.TimeCreated)>#1/1/2004 11:20:6#
And (Invoice.TimeCreated)<#3/1/2004 11:20:6#))
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";


What do you think it ought to be doing which it's not? You need to
double up on " when using verbatim string literals though.


Ah the old double quotes. I spend too much time not programming these days,
takes me a day or so to get back into the swing of things.

That's my excuse.

Thanks Jon!
Nov 16 '05 #3
On Fri, 07 May 2004 14:57:03 GMT, Jimbo wrote:
Thanks Jon!


Gah, this query works in access but not in code:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
[""blah1""],
Sum(InvoiceLine.InvoiceLineQuantity) AS [""blah2""]
FROM Invoice,
InvoiceLine
WHERE Invoice.TxnID = [InvoiceLine].[TxnID]
AND InvoiceLine.InvoiceLineQuantity > 0
AND Invoice.TimeCreated >#1/1/2003 11:20:6#
And Invoice.TimeCreated<#3/1/2004 11:20:6#
AND InvoiceLine.InvoiceLineItemRefFullName like '%RIHT/150/50/'
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";

DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sql,DB.Connection());
da.Fill(ds);
return ds;

Any ideas?
Nov 16 '05 #4
Jimbo,

You should be creating a parameterized query and then passing the
parameters for the query yourself. This way, you won't get hung up on the
formatting of the different types in Access (or any other provider, for that
matter).

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

"Jimbo" <bl**@example.com> wrote in message
news:E7***********************@news.easynews.com.. .
On Fri, 07 May 2004 14:57:03 GMT, Jimbo wrote:
Thanks Jon!


Gah, this query works in access but not in code:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
[""blah1""],
Sum(InvoiceLine.InvoiceLineQuantity) AS [""blah2""]
FROM Invoice,
InvoiceLine
WHERE Invoice.TxnID = [InvoiceLine].[TxnID]
AND InvoiceLine.InvoiceLineQuantity > 0
AND Invoice.TimeCreated >#1/1/2003 11:20:6#
And Invoice.TimeCreated<#3/1/2004 11:20:6#
AND InvoiceLine.InvoiceLineItemRefFullName like '%RIHT/150/50/'
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";

DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sql,DB.Connection());
da.Fill(ds);
return ds;

Any ideas?

Nov 16 '05 #5
On Fri, 07 May 2004 15:42:28 GMT, Jimbo wrote:
On Fri, 07 May 2004 14:57:03 GMT, Jimbo wrote:
Thanks Jon!


Gah, this query works in access but not in code:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

string sql = @"SELECT InvoiceLine.InvoiceLineItemRefFullName AS
[""blah1""],
Sum(InvoiceLine.InvoiceLineQuantity) AS [""blah2""]
FROM Invoice,
InvoiceLine
WHERE Invoice.TxnID = [InvoiceLine].[TxnID]
AND InvoiceLine.InvoiceLineQuantity > 0
AND Invoice.TimeCreated >#1/1/2003 11:20:6#
And Invoice.TimeCreated<#3/1/2004 11:20:6#
AND InvoiceLine.InvoiceLineItemRefFullName like '%RIHT/150/50/'
GROUP BY InvoiceLine.InvoiceLineItemRefFullName;";

DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sql,DB.Connection());
da.Fill(ds);
return ds;

Any ideas?


IDIOT!

Always use try and catch! I had the wrong db path.
Nov 16 '05 #6
On Fri, 7 May 2004 12:08:11 -0400, Nicholas Paldino [.NET/C# MVP] wrote:
Jimbo,

You should be creating a parameterized query and then passing the
parameters for the query yourself. This way, you won't get hung up on the
formatting of the different types in Access (or any other provider, for that
matter).

Hope this helps.


Can Access do stored procedures....?
Nov 16 '05 #7
Jimbo,

I believe it can. I think that when you open up Access, and add a
"Query" it is exposed as a stored procedure.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jimbo" <bl**@example.com> wrote in message
news:gX***********************@news.easynews.com.. .
On Fri, 7 May 2004 12:08:11 -0400, Nicholas Paldino [.NET/C# MVP] wrote:
Jimbo,

You should be creating a parameterized query and then passing the
parameters for the query yourself. This way, you won't get hung up on the formatting of the different types in Access (or any other provider, for that matter).

Hope this helps.


Can Access do stored procedures....?

Nov 16 '05 #8
Jimbo <bl**@example.com> wrote:
You should be creating a parameterized query and then passing the
parameters for the query yourself. This way, you won't get hung up on the
formatting of the different types in Access (or any other provider, for that
matter).

Hope this helps.


Can Access do stored procedures....?


You don't need to use stored procedures to do parameterised queries.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9

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

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
8
by: junky_fellow | last post by:
what would be the output for the following piece of code ? if ( "hello" == "hello" ) printf("True\n"); else printf("False\n"); What is the reason for that ?
5
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
5
by: polas | last post by:
Good morning, I have a quick question to clear up some confusion in my mind. I understand that using a string literal in a declaration such as char *p = "string literal" declares a pointer to...
4
by: zaimoni | last post by:
I've already calculated that the following are valid and should not error, as both just end up with the character literal 'A' being their control expression. The unspecified value of the char*...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.