- Joined
- 31 Dec 2003
- Posts
- 5,172
- Location
- Barrow-In-Furness
I'm using a detailsview to insert some information, i'll give a scenario to explain the problem...
A user inserts some information for a paticular date, they complete three fields (Date, TimeCode, Hours). If they then insert more information for the same date and same time code, there will be duplicate entries in the database for that date and timecode, meaning when I fetch the data it will be messed up.
I'm trying to check if any data exists for the selected date and timecode when the user inserts the information, the code i've come up with doesn't work though.
I've tried using...
On the line i've highlighted I get the error below when the user attempts to insert:
"Conversion from string "34" to type 'Date' is not valid."
Any help is appreciated
A user inserts some information for a paticular date, they complete three fields (Date, TimeCode, Hours). If they then insert more information for the same date and same time code, there will be duplicate entries in the database for that date and timecode, meaning when I fetch the data it will be messed up.
I'm trying to check if any data exists for the selected date and timecode when the user inserts the information, the code i've come up with doesn't work though.
I've tried using...
Code:
Protected Sub InsertHoursDetailsView_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles InsertHoursDetailsView.ItemInserting
Dim hoursAdapter As New ManHoursTableAdapters.tblHoursTableAdapter()
Dim hours As ManHours.tblHoursDataTable = hoursAdapter.GetHours()
For Each dr As System.Data.DataRow In hours.Rows()
[B][COLOR="Red"] If e.Values("Date") And e.Values("TimeCode") = dr("Date") And dr("TimeCode") Then[/COLOR][/B] e.Cancel = True
ConfirmationLabel.ForeColor = Drawing.Color.Red
ConfirmationLabel.Text = "Entry for this time code and date already exists, please check your logged hours if you wish to modify it"
End If
Next
End Sub
On the line i've highlighted I get the error below when the user attempts to insert:
"Conversion from string "34" to type 'Date' is not valid."
Any help is appreciated
