473,382 Members | 1,464 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,382 software developers and data experts.

Date in VB.NET vs. MSAccess and SELECT

I have a calendar on a simple windows form and when I choose a date it will put the date into a textbox with the format YYYY-MM-DD

When I choose a date i look up in a MSAccess database if there is any appointments for the selected date.

In the file (where the database query is in) calendar.xsd i can use the query below and all my appontments is listed in my datagrid.
<CommandText>SELECT * FROM tbNotification</CommandText>

But If I want to use the selected date that I have in my textbox, i get an error saying that "There is some values or parameters missing" (a simple translation from Swedish, don´t know the exact English translation). The Query I try to use is the one below:
<CommandText>SELECT * FROM tbNotification WHERE ([Date] = '#'+txtSelDate+'#')</CommandText>

I have tried:
- ALOT of syntaxes in the query string for the ## around the date
- putting the date as String, as Date etc etc
- putting the date as a variable (selDate = txtSelDate.text)

I have now tried everything I can think of. Does anyone of you guys a solution for my problem?

I'm extremely thankful for any help!

Have a nice easter! :)
Apr 1 '10 #1
14 6656
CroCrew
564 Expert 512MB
Hello bixfeldt,

In your Access database how is the field “Date” being stored? Text or Date/time?

CroCrew~
Apr 5 '10 #2
I have tried both Date/Time and Text but for the moment I store it as Text, not in Date/Time format.
Apr 5 '10 #3
CroCrew
564 Expert 512MB
Well the correct way is to store it as a Date/Time. Also “Date” is a reserved word and should not be used as your field name. Be clever with your field names. Like “NotificationDate”.

With that said let us know how you’re going to store it and the name of the field and we will try to provide you with your answer. Also, if you are going to store the data as a “text” give us some examples of what you have stored.

Again, I personally would not store dates as text.

CroCrew~
Apr 5 '10 #4
Hi,
Thanks for trying to help me! I have now renamed the column name from Date to notificationDate to avoid any problems with reserved words. I have also changed it to Date/Time instead of Text. The correct date format for Sweden is yyyy-mm-dd, so I save the dates as this into the database, for example 2010-01-01.

One "problem" that may be involved is that I have to use the character # before and after the date when working toward an Access database.

I hope this information is understandable. :)

Thanks in advance for you help!
Apr 6 '10 #5
I forgott to include the code below:
In the Form_Onload event in frmCalendar I can use the code below to show all entries in the database:

<!-- --------------------------------------------------------------------------------------------------- -->
txtSelDate.Text = MonthCalendar1.SelectionStart
lblCalMonth.Text = DatePart(DateInterval.Month, MonthCalendar1.SelectionStart)
lblCalDay.Text = DatePart(DateInterval.Day, MonthCalendar1.SelectionStart)
selDate = FormatDateTime(txtSelDate.Text, DateFormat.ShortDate)
txtSelDate.Text = MonthCalendar1.TodayDate
selDate = FormatDateTime(txtSelDate.Text, DateFormat.ShortDate)
selDate = "#" & selDate & "#"
lblCalMonth.Text = DatePart(DateInterval.Month, MonthCalendar1.TodayDate)
lblCalDay.Text = DatePart(DateInterval.Day, MonthCalendar1.TodayDate)
Me.TbNotificationTableAdapter.Fill(Me.CalendarData Set.tbNotification)
<!-- --------------------------------------------------------------------------------------------------- -->

And the SELECT statement in the calendarDataSet.xsd is as below:

<!-- --------------------------------------------------------------------------------------------------- -->
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>SELECT ID, NotificationDate, Notification, SE, [NO], DK, FI, PL, HK FROM tbNotification</CommandText>
<Parameters />
</DbCommand>
</SelectCommand>
<!-- --------------------------------------------------------------------------------------------------- -->

The thing that I want to do is to replace the code above, in the calendarDataSet.xsd, with this one:

<!-- --------------------------------------------------------------------------------------------------- -->
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>SELECT ID, NotificationDate, Notification, SE, [NO], DK, FI, PL, HK FROM tbNotification WHERE NotificationDate = '"#"'+selDate+"#"'</CommandText>
<Parameters />
</DbCommand>
</SelectCommand>
<!-- --------------------------------------------------------------------------------------------------- -->

I hope this also makes it more possible to locate the problem. Thank you very much for your kind help!
Apr 6 '10 #6
CroCrew
564 Expert 512MB
As the wise Tlhintoq says:

TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

Thanks,
CroCrew~
Apr 6 '10 #7
CroCrew
564 Expert 512MB
Hello bixfeldt,

Within your Access database can you tell me how the “NotificationDate” data looks when you run “SELECT NotificationDate FROM tbNotification”. I know you want it to display in a Sweden format “yyyy-mm-dd” through your application but within your Access database when you run the query how does it look? “mm-dd-yyyy” or “yyyy-mm-dd”

CroCrew~
Apr 6 '10 #8
Hi,
God tip, with the wrap code (#)!
If I look into my Access database, it has the format "yyyy-mm-dd".

// Bixfeldt
Apr 6 '10 #9
One more thing that might be a problem:
In my .xsd-file, wich is a XML-file, I have the line
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, NotificationDate, Notification, SE, [NO], DK, FI, PL, HK FROM tbNotification WHERE NotificationDate = selDate
selDate is declared under Form_Load in Calender.vb. Can i reference to a declared value in a form from an XML-file?

Can this be the problem?
Apr 7 '10 #10
CroCrew
564 Expert 512MB
Hello bixfeldt,

Ok, with the changes you have made (changing the field name from “Date” to “NotificationDate” and changing the field type from “Text” to “Date/Time”) your SQL query should be:

SELECT * FROM tbNotification WHERE (NotificationDate = #1970-01-09#)

Don’t wrap the date with single quotes.

Hope this helps,
CroCrew~
Apr 7 '10 #11
Yes, that works. But i don´t want to put a static date value in the code, but pick it up from my textbox called txtselDate.

How is the syntax to use the value that I have in a textbox at the design view called frmCalendar. I have today the following code at the form page:
Expand|Select|Wrap|Line Numbers
  1. selDate = txtSelDate.Text
Then, the value above, I want to use in the SQL statement. It is this SQL-statement that I might belive is wrong:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbNotification WHERE (NotificationDate = #+ selDate +#
So, the problem is that I don't wabt to use a static value, but instead use the value that is given in the textbox. Do you understand what i mean?
Apr 7 '10 #12
CroCrew
564 Expert 512MB
Hello bixfeldt,

Your SQL query should be a string that you’re building.

Example:
“SELECT * FROM tbNotification WHERE (NotificationDate = #” & selDate & “#”

Disclaimer! This is an example. You should always use parameters to protect yourself from SQL injection attacks.

Hope this helps,
CroCrew~
Apr 7 '10 #13
It doesn´t work. I get the error messages below:
Character ' ', hexadecimal values 0x20 is illegal in an XML name
It seems that the character "&" is not allowed in an XML-file.

I want to remind of that the SQL statement is not in the code-behind vb-file but in the file called calendarDataSet.xsd that is an XML-file that Visual studio automatically creates when adding a dataset, binding source and table adapter. Visual Studio automatically creates SELECT, INSERT, UPDATE, DELETE commands and it is this commands that I try to manipulate because I just want to see the notification for a specific date, not all notifications in the database.
Apr 7 '10 #14
Isn't there any simple solution where I can put an SQL command in the code-behind for each button instead of using an XML file with the SQL statements? Do you have a better solution than using XML?
Apr 7 '10 #15

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

Similar topics

0
by: Scott Morford | last post by:
This is a followup to a question I posed last summer. http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&selm=3f451dd4%240%241095%247f8943f3%40newsreader.visi.com I'm developing a weed...
2
by: b. hotting | last post by:
Hi, Which msAccess SQL guru can help my out here? i would like a list of sales(count) per day per customer end result, something like: distinct(date), customer, cnt(ItemsSold) 20/5/2005, c1,...
5
by: Paul | last post by:
Hi, I am a self taught VBA programmer, and I'm trying to learn VB2005 Express (The price was right). I like the look of the treeview control, and I'd like to use it as a menu system for my users,...
3
by: SimYing | last post by:
Is there any way to read and query data from Microsoft Access? Actually, i had anapplication which build using Python, wxPython, NumArray and etc. Now i need to find a way to retrieve data from...
3
by: Icemokka | last post by:
Hi, I've got a table in MsAccess with 100+ fields. If I fill a tabletable with this table , change some values , get the update-command via commandbuilder , the update fails. This because the...
11
by: charvi | last post by:
i have a problem with dates i want to retrieve some records between two dates dates are input to two masked box.i have written the query like this rssearch.Open "select * from timesheet where sname...
11
by: robtyketto | last post by:
Greetings, I'm using Flash MX connecting to an MS Access database via JET. I've stored dates using Flash/Jet into my database as 'dd/mm/yyyy hh:mm:ss' into a DATE/TIME field. However I can't...
0
by: robtyketto | last post by:
Greetings, I'm using MDMZinc to insert/update records into an MSAccess database, many headaches have been caused by dates. Apparently the best method to avoid complication is to record date...
6
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
3
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.