473,405 Members | 2,404 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.

Simple Query Not Executing

Dang! A *simple* query doesn't run on my machine. I wrote a Data Access
Layer (DAL) in a dll that I am testing with the help of a console
application.

Here's the code. I am damn sure that my code is fine. I think my
problem has something to do with MSDAC or some service pack or some
stupid Windows patch missing on my machine.
public static void GetJetScalar()
{
//string SQL = "select [Category Name], [Description] FROM
Categories WHERE [Category ID] = 2";
string SQL = "select [Order ID], [Product] FROM [Order Details]
WHERE [Order ID] = 10248";
DataProvider provider = null;
CategoryShort cat = null;

try
{
provider = new DataProvider();
cat = (CategoryShort)provider.GetScalar(SQL);
if (cat != null)
Console.WriteLine("Name: " + cat.Name + "\n\nDescription: " +
cat.Description);
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
cat = null;
provider = null;
}
}

Here's the code for the GetScalar() implemented by the DataProvider
class:

public System.Object GetScalar(string SQL)
{
System.Object ret = null;

if (this._connection.UnderlyingConnection == null)
{
System.Exception ex = new DatabaseTypeNotSupportedException();
_log.Write(new LogEntry(ex), true);
throw ex;
}

if (this._connection.Database == Databases.MSAccess)
ret = (new OleDbCommand(SQL,
(OleDbConnection)this._connection.UnderlyingConnec tion)).ExecuteScalar();
else if (this._connection.Database == Databases.SQLServer)
ret = (new SqlCommand(SQL,
(SqlConnection)this._connection.UnderlyingConnecti on)).ExecuteScalar();

return ret;
}
I get an exception that says: "No value provided for one or more
required parameters." I am trying it on the Northwind database only to
test it. I tried a query two or three queries, all syntactically
correct, but they all yeild the same exception as their result.

Aug 7 '06 #1
3 1951
ExecuteScalar() only returna single value but your SQL statement "select
[Order ID], [Product] FROM [Order Details]..."
http://msdn2.microsoft.com/en-us/lib...ar(d=ide).aspx

Use ExecuteNonQuery or others instead.

chanmm

"Water Cooler v2" <wt*****@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Dang! A *simple* query doesn't run on my machine. I wrote a Data Access
Layer (DAL) in a dll that I am testing with the help of a console
application.

Here's the code. I am damn sure that my code is fine. I think my
problem has something to do with MSDAC or some service pack or some
stupid Windows patch missing on my machine.
public static void GetJetScalar()
{
//string SQL = "select [Category Name], [Description] FROM
Categories WHERE [Category ID] = 2";
string SQL = "select [Order ID], [Product] FROM [Order Details]
WHERE [Order ID] = 10248";
DataProvider provider = null;
CategoryShort cat = null;

try
{
provider = new DataProvider();
cat = (CategoryShort)provider.GetScalar(SQL);
if (cat != null)
Console.WriteLine("Name: " + cat.Name + "\n\nDescription: " +
cat.Description);
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
cat = null;
provider = null;
}
}

Here's the code for the GetScalar() implemented by the DataProvider
class:

public System.Object GetScalar(string SQL)
{
System.Object ret = null;

if (this._connection.UnderlyingConnection == null)
{
System.Exception ex = new DatabaseTypeNotSupportedException();
_log.Write(new LogEntry(ex), true);
throw ex;
}

if (this._connection.Database == Databases.MSAccess)
ret = (new OleDbCommand(SQL,
(OleDbConnection)this._connection.UnderlyingConnec tion)).ExecuteScalar();
else if (this._connection.Database == Databases.SQLServer)
ret = (new SqlCommand(SQL,
(SqlConnection)this._connection.UnderlyingConnecti on)).ExecuteScalar();

return ret;
}
I get an exception that says: "No value provided for one or more
required parameters." I am trying it on the Northwind database only to
test it. I tried a query two or three queries, all syntactically
correct, but they all yeild the same exception as their result.

Aug 7 '06 #2

chanmm wrote:
ExecuteScalar() only returna single value but your SQL statement "select
[Order ID], [Product] FROM [Order Details]..."
http://msdn2.microsoft.com/en-us/lib...ar(d=ide).aspx

Use ExecuteNonQuery or others instead.

chanmm


You're missing the point. This is a *known* exception, which, in my
vast experience, I have encountered many times and resolved by
installing some update for the data access components. Only this time,
I do not know which one.

The DataReader works just fine. The only problem is with the
disconnected objects (DataSet/Scalars). The same code, however, works
perfectly on my laptop.

About your specific advise, I am sorry to say that you must read your
own advise carefully before you give it out misleading people. The MSDN
says:

"Executes the query, and returns the first column of the first row in
the result set returned by the query. Additional columns or rows are
ignored."
Correct Interpretation: You may execute any select query but it will
fetch the DataTable[0][0] result for the results of that query.

And ExecuteNonQuery() is not for "select" statements. Kindly read the
documentation thoroughly. It is for INSERT, UPDATE, DELETE (non-query
SQL statements, thereby meaning, statements that do *not* query data
but rather modify it).

Aug 7 '06 #3
Walter,

Can you give the next time a complete problem description. This as you do
now is in my opinion very very much misleading.

I did not give an answer, I was expecting a reply from you as you have now
given to Chanm. We are not here to be demotivated by you.

I agree completely whit Chanm, your statements are strange. The
executescalar is meant to return *one* (the first) value of your select.
Therefore that is at least misleading as well.

As thirth misleading part in your question you have outcommented code,
simply removing that in the message would help others better to help you.

Just to motivate Chanm again and let him/here not be demotivated by you

Cor

"Water Cooler v2" <wt*****@yahoo.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
>
chanmm wrote:
>ExecuteScalar() only returna single value but your SQL statement "select
[Order ID], [Product] FROM [Order Details]..."
http://msdn2.microsoft.com/en-us/lib...ar(d=ide).aspx

Use ExecuteNonQuery or others instead.

chanmm

You're missing the point. This is a *known* exception, which, in my
vast experience, I have encountered many times and resolved by
installing some update for the data access components. Only this time,
I do not know which one.

The DataReader works just fine. The only problem is with the
disconnected objects (DataSet/Scalars). The same code, however, works
perfectly on my laptop.

About your specific advise, I am sorry to say that you must read your
own advise carefully before you give it out misleading people. The MSDN
says:

"Executes the query, and returns the first column of the first row in
the result set returned by the query. Additional columns or rows are
ignored."
Correct Interpretation: You may execute any select query but it will
fetch the DataTable[0][0] result for the results of that query.

And ExecuteNonQuery() is not for "select" statements. Kindly read the
documentation thoroughly. It is for INSERT, UPDATE, DELETE (non-query
SQL statements, thereby meaning, statements that do *not* query data
but rather modify it).

Aug 7 '06 #4

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

Similar topics

1
by: AaronV | last post by:
Hello, I'd like to get the time it took a query to execute. Is there a PHP or MySQL function that would return the execute-time of the query into a useable format? Similar to the way Google...
0
by: tukaram.thatikonda | last post by:
Hi Guys, I have written a small windows application in VB.Net to test ADO.Net performance while executing long running query. The query works most of the time but fails sometime. I am trying...
1
by: T Jones | last post by:
Hello everybody! I hope someone can give hint on this, I'm very confused right now. Our program runs on a DB2-AS/400-System, we're connecting via an EasyCom-IDAPI-BDE (Borland Database...
3
by: Nils Magnus Englund | last post by:
Hi, I've made a HttpModule which deals with user authentication. On the first request in a users session, it fetches data from a SQL Server using the following code: using (SqlConnection...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
3
by: Water Cooler v2 | last post by:
Dang! A *simple* query doesn't run on my machine. I wrote a Data Access Layer (DAL) in a dll that I am testing with the help of a console application. Here's the code. I am damn sure that my...
2
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to...
3
by: diego | last post by:
Greetings everyone! Is there a way to stop query analyzer from processing remaining query statements? Let's say i have the following query in query analyzer: query statements if condition...
3
by: prabhas | last post by:
I want to swap two tuples in a table, using a single , simple query. No SELECT query allowed, no inner queries allowed. No PL/SQL allowed. Do you have any idea how to do this? e.g. my current...
4
by: naveenpadmadas | last post by:
Hi, i have a simple query. I was practising a c program using function by just calling the function. The called function are defined with only printf statements. I tried executing the same program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.