473,944 Members | 21,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting numeric value with int

6 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. public void Extract_Close_Table_All_By_Date(int Start_Date)
  2. {
  3. try
  4. {
  5. OleDbConnection DB_Connection = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\HOST 000.MDB");
  6. DB_Connection.Open();
  7. //TO CONTAIN RELATED DATA TABLES, ROWS, & COLUMNS
  8. DataSet DB_DataSet = new DataSet();
  9. //EXTRACT TABLE
  10. OleDbDataAdapter Adapter_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ZONE] WHERE [TABLE_START_DATE] >= Start_Date", DB_Connection);
  11. //    OleDbDataAdapter Adapter_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ZONE] WHERE [TABLE_START_DATE] = 20070423", DB_Connection);
  12. Adapter_Zone.Fill(DB_DataSet, "CLOSED_TABLE_ZONE");
  13. //EXTRACT TABLE ITEMS
  14. OleDbDataAdapter Item_Zone = new OleDbDataAdapter("SELECT * FROM [CLOSED_TABLE_ITEMS]", DB_Connection);
  15. Item_Zone.Fill(DB_DataSet, "CLOSED_TABLE_ITEMS");
  16. //RELATION
  17. DataRelation Table_Relations = DB_DataSet.Relations.Add("CLOSED_TABLE_ITEMS", DB_DataSet.Tables["CLOSED_TABLE_ZONE"].Columns["TABLE_ID"], 
  18. DB_DataSet.Tables["CLOSED_TABLE_ITEMS"].Columns["TABLE_ID"],false);
  19. //
  20. Table_Relations.Nested = true;
  21.  
Feb 12 '09 #1
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
Feb 12 '09 #2
Mikesinfo
6 New Member
Thank you for your reponse, but do you or anyone know where I can find the information to pass by value instead?
Feb 13 '09 #3
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:
Expand|Select|Wrap|Line Numbers
  1. DateTime Start_Date = new DateTime(2007, 04, 23);
  2. String Start_Date_Text = Start_Date.ToString("yyyyMMdd");
  3.  
If Start_Date is (int)20070423, then you can also write:
Expand|Select|Wrap|Line Numbers
  1. String Start_Date_Text = Start_Date.ToString();
  2.  
Feb 13 '09 #4
Mikesinfo
6 New Member
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.
Feb 13 '09 #5
Plater
7,872 Recognized Expert Expert
Here is what I suggest:
http://www.google.com/search?source=...arch&aq=-1&oq=
Feb 13 '09 #6
vekipeki
229 Recognized Expert New Member
@Mikesinfo
If this works:

Expand|Select|Wrap|Line Numbers
  1. String sqlQuery =
  2.    "SELECT * FROM [CLOSED_TABLE_ZONE]
  3.     WHERE [TABLE_START_DATE] = 20070423";
Then I don't see a reason why this shouldn't work:

Expand|Select|Wrap|Line Numbers
  1. String sqlQuery =
  2.    "SELECT * FROM [CLOSED_TABLE_ZONE]
  3.     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.
Feb 13 '09 #7
Mikesinfo
6 New Member
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'
Feb 13 '09 #8
Mikesinfo
6 New Member
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
Feb 13 '09 #9
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.
Feb 13 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
14826
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. ...
0
3187
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...
1
2819
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:
7
3010
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...
2
2658
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...
13
3751
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...
3
1488
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...
6
1743
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
16
38064
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?
0
10147
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, 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...
0
11547
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, 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...
0
11136
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 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...
1
11310
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,...
0
9870
agi2029
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...
0
7399
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();...
0
6093
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...
0
6315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3520
bsmnconsultancy
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...

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.