Re: SQL WHERE Command Help [C# Win]



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.CreateCommand();

//Initialize SQL SELECT command to retrieve data

myCommand.CommandText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = @cat";

myCommand.Parameters.Add(new OleDbParameter ("@cat",Extract_Parameter));



//This Syntax works, but opens your program up too Syntax Attacks "sql
injection"

//myCommand.CommandText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = '" + Extract_Parameter + "'";



//Create DataReader

OleDbDataReader myDataReader = myCommand.ExecuteReader();



MikeY

"MikeY" <mikesinfo@xxxxxxxx> wrote in message
news:uthV7f$2GHA.1040@xxxxxxxxxxxxxxxxxxxxxxx
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_Parameter

{

get

{

return extract_parameter;

}

set

{

extract_parameter = value;

}

}



public void Load_Lunch_Menu_Extract()

{

try

{

//Connetion to DataBase

OleDbConnection myConnection = new OleDbConnection(@"Provider =
Microsoft.Jet.OLEDB.4.0;Data Source = C:\Host 017.mdb");

//Open Connection to DataBase

myConnection.Open();

//SQL Command for myConnection

OleDbCommand myCommand = myConnection.CreateCommand();

//Initialize SQL SELECT command to retrieve data

myCommand.CommandText = "SELECT * FROM [Food Lunch Menu] WHERE
[ItemCatagory] = 'Extract_Parameter'";

//Create DataReader

OleDbDataReader myDataReader = myCommand.ExecuteReader();

//Cycle through data and display

test = new ArrayList();



while(myDataReader.Read())

{

}

//Close Connection to DataBase

myDataReader.Close();

myConnection.Close();



test.Sort(0, test.Count, new ArrayList_Sort());

}

catch(Exception myException)

{

MessageBox.Show(myException.Message);

}

}

}



Thanks,



MikeY




.



Relevant Pages

  • Re: Cannot use a CONTAINS or FREETEXT predicate on table...
    ... command from the context of the database I wish to publish. ... This database is not enabled for publication. ... The replication agent has been successfully started. ... Source: Microsoft SQL Native Client ...
    (microsoft.public.sqlserver.replication)
  • Re: SQL update in SQL database issue
    ... I am thinking if i change the database from Foxpro to SQL or MS Access, ... program installation require, if a table corrupted, user can just attach ... should I use SQL pass through command to update the Foxpro Database or ...
    (microsoft.public.fox.programmer.exchange)
  • Help needed, ASP.NET caching with SQL Server doesnt work
    ... I'm trying to use ASP.NET caching with my web site and SQL Server, ... First I run the aspnet_regsql tool on the command line succesfully to enable ... the database for cache notification: ... dependency matches exactly the table name used in cache notification ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Backup SQLExpress 2005 in code
    ... The backup statements can be done as DDL (Data Definition Language, a form of SQL Script), so you can send the commands to the database via that method. ... One option is to send as a SQL command, but that is not the best option, as you lock up a thread while the command is running. ...
    (microsoft.public.dotnet.framework)
  • Re: Accesing structures data (getting lengthy!)
    ... According to the syntax you ... assignment statement just won't stand out amongst all the other ... meaningless dummy variables that you have to keep track of. ... comparitively easy to pick out of a long, boring, command line history, ...
    (comp.soft-sys.matlab)