| Author |
Topic Search Topic Options
|
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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
|
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |