473,395 Members | 1,383 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,395 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 1199
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...
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
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: 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...
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
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
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...

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.