troubleshooting Question

Date problem using LINQ to SQL

Avatar of clearchannel
clearchannel asked on
.NET ProgrammingASP.NET
14 Comments1 Solution814 ViewsLast Modified:
I thought I had fixed my problem but it seems it is still there... I am utterly rubbish with dates when it comes to db fields etc :(

I have 3 date/time fields: InChargeDate, WorkDate, WorkTime. obviously form the name you can work out whether it is a date or time. In the SQL db ALL 3 fields are SMALLDATETIME.

When I loop through the dataset using LINQ2SQL and a stored procedure it should be inserted into my database. BUT when the date/time fields are empty or of the wrong format it causes a cast error which I do not know how to rectify. I am guessing I need to check the dates/times for a type or empty value but not sure exactly what I need to code.

I would be grateful if someone could asisst me as I crap with the whole datetime thiing.
.aspx code
=========
While i < dsPictures.Tables(0).Rows.Count
                        Dim newPicture As New MOMs_Image With {.PictureName = dsPictures.Tables(0).Rows(i)("PictureName"), .WorkOrderNo = dsPictures.Tables(0).Rows(i)("WorkOrderNo"), .IssueNo = dsPictures.Tables(0).Rows(i)("IssueNo"), .RoundName = dsPictures.Tables(0).Rows(i)("RoundName"), .OperativeName = dsPictures.Tables(0).Rows(i)("OperativeName"), .InChargeDate = dsPictures.Tables(0).Rows(i)("InChargeDate"), .LocationNo = dsPictures.Tables(0).Rows(i)("LocationNo"), .PanelNo = dsPictures.Tables(0).Rows(i)("PanelNo"), .WorkDate = dsPictures.Tables(0).Rows(i)("WorkDate"), .WorkTime = dsPictures.Tables(0).Rows(i)("WorkTime"), .DesignName = dsPictures.Tables(0).Rows(i)("DesignName"), .GPSLatitude = dsPictures.Tables(0).Rows(i)("GPSLatitude"), .GPSLongitude = dsPictures.Tables(0).Rows(i)("GPSLongitude"), .MOMSFeedback = dsPictures.Tables(0).Rows(i)("MOMSFeedback"), .PlanNum = dsPictures.Tables(0).Rows(i)("PlanNum"), .NameStreet = dsPictures.Tables(0).Rows(i)("NameStreet"), .Address1 = dsPictures.Tables(0).Rows(i)("Address1"), .Address2 = dsPictures.Tables(0).Rows(i)("Address2"), .City = dsPictures.Tables(0).Rows(i)("City"), .Country = sCountry}
                        pdc.MOMs_Images.InsertOnSubmit(newPicture)
 
                        If Exists(Server.MapPath("/temp/" & sCountry & "/" & dsPictures.Tables(0).Rows(i)("PictureName"))) Then
                            File.Move(Server.MapPath("/temp/" & sCountry & "/" & dsPictures.Tables(0).Rows(i)("PictureName")), Server.MapPath("/imported/" & sCountry & "/" & dsPictures.Tables(0).Rows(i)("PictureName")))
                        End If
 
                        i = i + 1
                    End While
                    pdc.SubmitChanges()
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros