Hi everyone,
I'm having problems with my WHERE Clause syntax with in my SQL CommandText.
The error that it is display is "You Have No Data". My problem lies with in
the WHERE clause not finding up my passed variable from my get/set function.
I have done watch's on the variable and the data name I'm looking for is
present.
I thought my syntax was correct, but maybe it's not. Can someone look it
over and see if there is anything wrong with it and give me a correct
solution if there is something wrong. Thank you all in advance.
public string Extract_Paramet er
{
get
{
return extract_paramet er;
}
set
{
extract_paramet er = value;
}
}
public void Load_Lunch_Menu _Extract()
{
try
{
//Connetion to DataBase
OleDbConnection myConnection = new OleDbConnection (@"Provider =
Microsoft.Jet.O LEDB.4.0;Data Source = C:\Host 017.mdb");
//Open Connection to DataBase
myConnection.Op en();
//SQL Command for myConnection
OleDbCommand myCommand = myConnection.Cr eateCommand();
//Initialize SQL SELECT command to retrieve data
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = 'Extract_Parame ter'";
//Create DataReader
OleDbDataReader myDataReader = myCommand.Execu teReader();
//Cycle through data and display
test = new ArrayList();
while(myDataRea der.Read())
{
}
//Close Connection to DataBase
myDataReader.Cl ose();
myConnection.Cl ose();
test.Sort(0, test.Count, new ArrayList_Sort( ));
}
catch(Exception myException)
{
MessageBox.Show (myException.Me ssage);
}
}
}
Thanks,
MikeY 3 2743
Mike,
When you want to parameterize a query, you have to manually add the
parameter to the command, as well as set the value. The command does not
reflect on anything to get the value you are expecting.
What you need to do is this:
OleDbCommand myCommand = myConnection.Cr eateCommand();
//Initialize SQL SELECT command to retrieve data
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = '@itemCategory' ";
// Add the parameter.
myCommand.Param eters.Add(this. Extract_Paramet er);
The call to add should extract a parameter with the appropriate value
and then execute properly.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"MikeY" <mi*******@yaho .comwrote in message
news:ut******** ******@TK2MSFTN GP06.phx.gbl...
Hi everyone,
I'm having problems with my WHERE Clause syntax with in my SQL
CommandText. The error that it is display is "You Have No Data". My
problem lies with in the WHERE clause not finding up my passed variable
from my get/set function. I have done watch's on the variable and the data
name I'm looking for is present.
I thought my syntax was correct, but maybe it's not. Can someone look it
over and see if there is anything wrong with it and give me a correct
solution if there is something wrong. Thank you all in advance.
public string Extract_Paramet er
{
get
{
return extract_paramet er;
}
set
{
extract_paramet er = value;
}
}
public void Load_Lunch_Menu _Extract()
{
try
{
//Connetion to DataBase
OleDbConnection myConnection = new OleDbConnection (@"Provider =
Microsoft.Jet.O LEDB.4.0;Data Source = C:\Host 017.mdb");
//Open Connection to DataBase
myConnection.Op en();
//SQL Command for myConnection
OleDbCommand myCommand = myConnection.Cr eateCommand();
//Initialize SQL SELECT command to retrieve data
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = 'Extract_Parame ter'";
//Create DataReader
OleDbDataReader myDataReader = myCommand.Execu teReader();
//Cycle through data and display
test = new ArrayList();
while(myDataRea der.Read())
{
}
//Close Connection to DataBase
myDataReader.Cl ose();
myConnection.Cl ose();
test.Sort(0, test.Count, new ArrayList_Sort( ));
}
catch(Exception myException)
{
MessageBox.Show (myException.Me ssage);
}
}
}
Thanks,
MikeY
Hi,
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = 'Extract_Parame ter'";
Here is where your problem is, you are saying that {itemcategory] has to be
"Extran_Paramet er"
you could change it to:
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = '" + Extract_Paramet er + "'";
I would suggest you to use parameterized queries it will avoid such problems
and avoid the risk of sql injection
This is how it would looks like:
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = @cat";
myCommand.Param eters.Add( "@cat" SqlDataType.Var char, 50).Value =
Extract_Paramet er ;
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Just typing an update for others that might need this line of code. Hope
this helps others as these two fellows helped me. Txs Again.
//SQL Command for myConnection
OleDbCommand myCommand = myConnection.Cr eateCommand();
//Initialize SQL SELECT command to retrieve data
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = @cat";
myCommand.Param eters.Add(new OleDbParameter ("@cat",Extract _Parameter));
//This Syntax works, but opens your program up too Syntax Attacks "sql
injection"
//myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = '" + Extract_Paramet er + "'";
//Create DataReader
OleDbDataReader myDataReader = myCommand.Execu teReader();
MikeY
"MikeY" <mi*******@yaho .comwrote in message
news:ut******** ******@TK2MSFTN GP06.phx.gbl...
Hi everyone,
I'm having problems with my WHERE Clause syntax with in my SQL
CommandText. The error that it is display is "You Have No Data". My
problem lies with in the WHERE clause not finding up my passed variable
from my get/set function. I have done watch's on the variable and the data
name I'm looking for is present.
I thought my syntax was correct, but maybe it's not. Can someone look it
over and see if there is anything wrong with it and give me a correct
solution if there is something wrong. Thank you all in advance.
public string Extract_Paramet er
{
get
{
return extract_paramet er;
}
set
{
extract_paramet er = value;
}
}
public void Load_Lunch_Menu _Extract()
{
try
{
//Connetion to DataBase
OleDbConnection myConnection = new OleDbConnection (@"Provider =
Microsoft.Jet.O LEDB.4.0;Data Source = C:\Host 017.mdb");
//Open Connection to DataBase
myConnection.Op en();
//SQL Command for myConnection
OleDbCommand myCommand = myConnection.Cr eateCommand();
//Initialize SQL SELECT command to retrieve data
myCommand.Comma ndText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = 'Extract_Parame ter'";
//Create DataReader
OleDbDataReader myDataReader = myCommand.Execu teReader();
//Cycle through data and display
test = new ArrayList();
while(myDataRea der.Read())
{
}
//Close Connection to DataBase
myDataReader.Cl ose();
myConnection.Cl ose();
test.Sort(0, test.Count, new ArrayList_Sort( ));
}
catch(Exception myException)
{
MessageBox.Show (myException.Me ssage);
}
}
}
Thanks,
MikeY
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paolo Scolamacchia |
last post by:
Hi everybody, this is my environment : Apache is installed on a Linux server
(RedHat9A) and
I launch the browser on a PC running WindowsXP to execute php scripts on the
Linux server.
I would run Win executables from this Linux-based Apache server.
Actually if I use exec() command running Linux commands, something like :
$command="mv /store1/www/file1.txt /store1/www/file2.txt";
exec($command, $ar_output, $res_command);
|
by: Oli Howson |
last post by:
Ok, I'm using php-win, and have the following file, c:\mail.php
<?
mail('email@myaddress.com','a test','a php-win cli test');
?>
When I go to start|run or cmd and type...
php-win -f c:/mail.php
|
by: EAS |
last post by:
Is there any way of using Python to open a command prompt?
|
by: Kenneth McDonald |
last post by:
For unfortunate reasons, I'm considering switching back to Win XP
(from OS X) as my "main" system. Windows has so many annoyances that
I can only compare it to driving in the Bay Area at rush hour (OS X
is like driving in Portland at rush hour--not as bad, but getting
there), but there are really only a couple of things that are really,
absolutely preventing me from making the switch. Number one is the
lack of a decent command line and...
|
by: Vlado |
last post by:
I have db2 7.2 on Win 2000, programing MS VB6.0
I update 1 field on 600 records - successfully, but if i update more then
600 records then i have err. mesage
SQL0952N Processing was cancelled due to
an interrupt. SQLSTATE=57014
T his is my query:
Update KC113DELO.DNEVNIK Set TTEMA='109 Po¾igi' Where IDDNEVNIKA>1000
| |
by: Jarod |
last post by:
Hey
I have already written a program that has a user interface, but I would like
to add some command line interface too. So if the user run it like:
program.exe paramater1
The program do something, but If not, the program normally run with windows
interface.
I tried Sub Main(args ... ) but I don't know how to connect it together.
Jarod
|
by: Ennio-Sr |
last post by:
Hi all!
I'm writing a script that presents the user with a numbered lines
menu, each line corresponding to a <case n> which executes a psql
command. As the psql-commands are very similar to each other (all of
them have the structure:
1.- psql mydb -x -c "SELECT * FROM tb_nm WHERE col_nm LIKE '%$k_r%'" )
I thought it was possible to shorten it, initializing a str with said
command at the beginning of the script and limiting the...
|
by: Csaba Gabor |
last post by:
I would like to use the AT command under Win XP to schedule (CLI)
php.exe. I thought it would be as easy as: AT 7:11 "php
c:\phpapps\himom.php". However, this gives me an error. My solution
is inducing the gag reflex in me, so perhaps someone can point out an
improvement.
himom.php (to show a Message Box) looks like so:
<?php
function popup ($text, $title="PHP popup", $timeout=4, $style=131120) {
$oWSH = new COM("WScript.Shell");
|
by: SAM689532 |
last post by:
I have DB2 v7.1.2 on IBM Z/OS
and DB2 V8.1.0.36 Level ID 01010106
Build Level s021023
with JDK 1.3.1 on my Windows platform.
I am trying to load some Arabic character data to our mainframe DB2 tables. the EBCDID CCSID is 420. WIN CCSID is 1256.
The data originally is from SQL Server. When I load the data to my Windows DB2, everything is fine. But when I export the data from my windows DB2 to an IXF file, and then import it to my...
|
by: Ojas |
last post by:
Hi!,
I just out of curiosity want to know how top detect the client side
application under which the script is getting run. I mean to ask the
how to know whether the script is running under Command Prompt or
Browser or some other application?
Ojas.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |