Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using the DateTime Control.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using the DateTime Control.

 Post Reply Post Reply Page  12>
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: Using the DateTime Control.
    Posted: 07 July 2004 at 1:23pm

:-) Keeping the ASP.NET boards hopping. As mentioned earlier, I'm working on a Today in History Script (I actually wrote one that works in ASP...and figured it'd probably be best to start where I left off)...Anyways, my problem this time is in using DateTime. I guess I'm doing something wrong? Any suggestions on where my code is wrong would be appreciated:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb


Public Class TodayEvents
  Inherits Page
  Protected lblTodayEvents as Label
   Private Sub Page_Load(sender as Object, e as EventArgs) Handles MyBase.Load
     Dim DBConnection as New OleDBConnection()
     DBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=civilwar.mdb"
     DBConnection.Open
     Dim DBReader as OleDBDataReader
     Dim TodaysDay as DateTime = DateTime.Now
     TodaysDay = TodaysDay.Day.ToString
     Dim TodaysMonth as DateTime= DateTime.Now
     TodaysMonth = TodaysMonth.Month.ToString
     Dim DBReadData as New OleDBCommand()
     DBReadData.Connection = DBConnection
     DBReadData.CommandText = "Select * from tblToday WHERE TodaysDay=mDay and TodaysMonth=mMonth"
     DBReader = DBReadData.ExecuteReader()
     DO WHILE DBReader.Read()
       lblTodayEvents.Text = lblTodayEvents.Text
    lblTodayEvents.Text &= "<tr><td>" & DBReader("mMonth") & "/"
    lblTodayEvents.Text &= DBReader("mDay") & "/"
    lblTodayEvents.Text &= DBReader("mYear") & " - "
    lblTodayEvents.Text &= DBReader("mEvent") & "<br>"
  Loop
  DBReader.Close()
  DBConnection.Close()
   End Sub
End Class

Respectfully,
David.

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 1:28pm

Just to highlight the code in question it is:
' Find today's date so it can be compared against data.
     Dim TodaysDay as DateTime = DateTime.Now
     TodaysDay = TodaysDay.Day.ToString
     Dim TodaysMonth as DateTime= DateTime.Now
     TodaysMonth = TodaysMonth.Month.ToString
Error is:
Cast from string "7" to type 'Date' is not valid.
Fun. :-P

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 1:31pm

Instead of

Dim TodaysDay as DateTime = DateTime.Now
     TodaysDay = TodaysDay.Day.ToString
     Dim TodaysMonth as DateTime= DateTime.Now
     TodaysMonth = TodaysMonth.Month.ToString

Use

Dim TodaysDay As String = Now.Day.ToString

Dim TodaysMonth As String = Now.Month.ToString

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 1:40pm

     ' Find today's date so it can be compared against data.
     Dim TodaysDay as String = Now.Day.ToString
     Dim TodaysMonth as String = Now.Month.ToString
Gives error:

Name 'Now' is not declared.
Respectfully,
David.

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 1:55pm

Try this:

Dim TodaysDay as String = DateTime.Now.Day.ToString
     Dim TodaysMonth as String = DateTime.Now.Month.ToString

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 2:05pm

Thanks Mart for your help. Its appreciated, however once again it threw an error...But a different one this time. Now its telling me:
No value given for one or more required parameters.
Here is the stack trace, I couldn't make any sense out of it:

[OleDbException (0x80040e10): No value given for one or more required parameters.]
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandli ng(Int32 hr) +41
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleRe sult(tagDBPARAMS dbParams, Object& executeResult) +122
    System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& ; executeResult) +92
    System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavio r behavior, Object& executeResult) +65
    System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(Command Behavior behavior, String method) +112
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +69
   System.Data.OleDb.OleDbCommand.ExecuteReader() +7
   TodayEvents.Page_Load(Object sender, EventArgs e) +226
   System.Web.UI.Control.OnLoad(EventArgs e) +55
   System.Web.UI.Control.LoadRecursive() +27
   System.Web.UI.Page.ProcessRequestMain() +731

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 2:29pm

You used 2 parameters in your SQL Query:

Select * from tblToday WHERE TodaysDay=mDay and TodaysMonth=mMonth

(mDay and mMonth)

You just need to add the value of the parameters to the OleDb command

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 07 July 2004 at 2:40pm
When you say I need to add the value to the command, what exactly do you mean? mDay and mMonth have different values depending on which entry in the database they are?
Respectfully,
David.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.