Hi everyone,
Hopefully this is the right forum to use.
I am programming in C# [Win forms] and I've been racking my brain and searching for the right answer to extract my information according to after a certain input date. the problem is that when I hard-code the numeric date, there is no problem at all and all requested information is displayed correctly. But when I try to pass the variable (parameter) as an integer as in the code that follows, the syntax generates this error "No value given for one or more required parameters".
Guess what I'm trying to say is what is the right code that I am missing to extract the tables. MS Access is the db and I am using C#. The fustrating Integer is "Start_Date ". There is also a blocked out code where I do have success with the hard-coded date.
Thank you all for any and all help. -
public void Extract_Close_Table_All_By_Date(int Start_Date)
-
{
-
try
-
{
-
OleDbConnection DB_Connection = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\HOST 000.MDB");
-
DB_Connection.Open();
-
//TO CONTAIN RELATED DATA TABLES, ROWS, & COLUMNS
-
DataSet DB_DataSet = new DataSet();
-
//EXTRACT TABLE
-
OleDbDataAdapter Adapter_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ZONE] WHERE [TABLE_START_DATE] >= Start_Date", DB_Connection);
-
// OleDbDataAdapter Adapter_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ZONE] WHERE [TABLE_START_DATE] = 20070423", DB_Connection);
-
Adapter_Zone.Fill(DB_DataSet, "CLOSED_TABLE_ZONE");
-
//EXTRACT TABLE ITEMS
-
OleDbDataAdapter Item_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ITEMS]", DB_Connection);
-
Item_Zone.Fill(DB_DataSet, "CLOSED_TABLE_ITEMS");
-
//RELATION
-
DataRelation Table_Relations = DB_DataSet.Relations.Add("CLOSED_TABLE_ITEMS", DB_DataSet.Tables["CLOSED_TABLE_ZONE"].Columns["TABLE_ID"],
-
DB_DataSet.Tables["CLOSED_TABLE_ITEMS"].Columns["TABLE_ID"],false);
-
//
-
Table_Relations.Nested = true;
-
10 2362 Plater 7,872
Recognized Expert Expert
Well it looks like you have some string creation issues.
In this line:
OleDbDataAdapte r Adapter_Zone = new OleDbDataAdapte r("SELECT * FROM [CLOSED_TABLE_ZO NE] WHERE [TABLE_START_DAT E] >= Start_Date", DB_Connection);
You are actually passing the WORD "Start_Date " instead of the value of Start_Date
Thank you for your reponse, but do you or anyone know where I can find the information to pass by value instead?
vekipeki 229
Recognized Expert New Member
Why is your Start_Date an integer? Do you know how to get "20070423" from your int number?
E.g. if Start_Date was a DateTime variable, you could easily convert it: - DateTime Start_Date = new DateTime(2007, 04, 23);
-
String Start_Date_Text = Start_Date.ToString("yyyyMMdd");
-
If Start_Date is (int)20070423, then you can also write: - String Start_Date_Text = Start_Date.ToString();
-
Hi Vekipeki,
Unfortuntily I am struggling with trying to extract my number (dates) from the databes with my integers (Start_Date). I don't know the right syntax.
The reason that I made the value an integer is because of doing various date extractions. ie everything after and including that particular date (a range of dates). So that is why I made the MS database value as a number and not text and in the format in 20070423. This would be great if I could just hard code the extraction date, but the date would change upon every users query. Or even if I was looking for a name (string), but alas I am not.
If that makes sense.
Plater 7,872
Recognized Expert Expert vekipeki 229
Recognized Expert New Member @Mikesinfo
If this works: - String sqlQuery =
-
"SELECT * FROM [CLOSED_TABLE_ZONE]
-
WHERE [TABLE_START_DATE] = 20070423";
Then I don't see a reason why this shouldn't work: - String sqlQuery =
-
"SELECT * FROM [CLOSED_TABLE_ZONE]
-
WHERE [TABLE_START_DATE] = " + Start_Date.ToString();
Presuming that (Start_Date == 20070423).
Note that this is a quick way, but NOT a recommended (safe) way to do it (although if Start_Date is an integer then I cannot think of a possible injection attack). Check this for an example: http://www.csharp-station.com/Tutori.../Lesson06.aspx
Examples with hard-coded values are usually given for demonstration only - SQL queries are intended to be built in run-time.
Txs Plater,
I have been to some of the sites, and will look at more of the ones you linked through google, but the ones that I've previously been too ie .w3schools.com, when it comes to numeric values, they hard-code the values in:
Unfortunitly, I am not looking to hard code dates in because they do change per query. But once again, thank you & I'll keep searching the google link and hopefully come up the the solution.
This is correct:SELECT * FROM Persons WHERE Year=1965
This is wrong:SELECT * FROM Persons WHERE Year='1965'
Ahhhhh Vekipeki,
You did it, after all this head-aches you've done it, thank you very much. It was just the "+" that was missing. ie "+ Start_Date". You have made my day and much appreciated.
Unfortunitly all these hassles would be avoided if they only but real time solutions in these programming books.
thank you and all others once again
Mike
vekipeki 229
Recognized Expert New Member
I recommend you read this article anyway, that is a proper way to do it.
Otherwise, simple concatenating strings might allow an attacker to insert his own SQL code and compromise your data. Check this link for an explanation: SQL Injection Attack.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: cpp_weenie |
last post by:
Given a std::string of the form "default(N)" where N is an integer number of
any length (e.g. the literal string might be "default(243)"), what is the
quickest way to extract the characters representing the integer into another
std::string? In the example above, I'd want to end up with a std:string
whose value is "243".
The substrings "default(" and ")" are invariant - they're always present in
the string I have to work with. ...
|
by: Mark Sisson |
last post by:
Hi all.
I'm working in C# and need to interrogate a JPEG to get it's metadata.
To test I created a jpg in photoshop and then used it's File Info
dialog to load up all kinds of metadata about the photograph like
author, keywords, jobname,
copywrite, yada yada yada. Now I want to get at that information from
C#.
I've been creating a System.Drawing.Bitmap object for my test jpg and
I do see 73 property items but the ids and value are all...
|
by: Cognizance |
last post by:
Hi gang,
I'm an ASP developer by trade, but I've had to create client side
scripts with JavaScript many times in the past. Simple things, like
validating form elements and such.
Now I've been assigned the task of extracting content from a given HTML
page. If anyone's familiar with the Yahoo! Store order confirmation
screen, I need to be able to grab the total amount from the table to
the right-hand side. (Sample File:
|
by: Raphi |
last post by:
Hi,
I'm trying to clean up a large database in Access. I have one field for
address, which needs to be broken up into Street Number, Street Name, and
Street Label (St., Road, etc.)
The problem is that the data is very dirty. So some addresses will be
standard "456 XYZ Road," while others won't have a number and will just say
"XYZ Industrial Park," meaning I can't just use Instr to search for the
first space because sometimes the...
|
by: Dirtyweeker |
last post by:
Hi,
I have a database which records fitness test results of pupils.
There are the usual name fields and then a series of fields holding results,
e.g. field BP1 and field BP2; each of these fields holds a test result in
numerical form. Let's assume BP1 value is 55 and BP2 value is 57.
My problem is that I want to have a report which will only give me the
highest result for that test for each pupil; I need to be able to extract
the...
| |
by: Randy |
last post by:
Is there any way to do this? I've tried tellg() followed by seekg(),
inserting the stream buffer to an ostringstream (ala os << is.rdbuf()),
read(), and having no luck.
The problem is, all of these methods EXTRACT the data at one
point or another. The other problem is there appears to be NO
WAY to get at the actual buffer pointer (char*) of the characters
in the stream. There is a way to get the streambuf object
associated with the...
|
by: Lazster |
last post by:
Hello People,
I am a newbie here, and if I make some stupid mistakes please forgive me :)
I have found this site very helpful, and was hoping someone could solve a problem I have.
I have created a module in Access, Office 2003. The module is supposed to extract numeric strings from a field on a form and place entries in a sub form.
The code below is how I have tried to do this...
|
by: george13lucky |
last post by:
Hi,
Please forgive my ignorance as i am a newbie on Access .
I have a field on in my table called Sch_Data with the following record .
3;875;646;697;1
3;875;712;770;1
3;53;880;893;1
4;4;697;712;1
|
by: giaro |
last post by:
Hi,
I'm doing some maths and I've just found that the standard library
does not provide a standard PI value. In older post I see everyone says
you must define it by yourself, but as some of the standard functions
are in fact supposed to return that value, I feel there must be a better
way. For example, here's what a google search returned:
float PI = std::atan(1.0f) * 4.0f;
Anything more accurate?
|
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |