string literal with sql

  • Thread starter Thread starter Jimbo
  • Start date Start date
J

Jimbo

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;";
 
Jimbo said:
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.
 
Jimbo said:
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!
 
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?
 
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]
- (e-mail address removed)

Jimbo said:
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?
 
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.
 
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....?
 
Jimbo,

I believe it can. I think that when you open up Access, and add a
"Query" it is exposed as a stored procedure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

simple SQL: select missing rows 4
Dealing with a null BLOB field 1
Windows 7 Duplicate files. 1
SQL query slow 37
Transposing 0
Subtotal GroupBy text string 2
Summary query in DLinq 6
Parse string expression and get result 10

Back
Top