Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have an application in which i have to take reports of the transaction done on particular date range
For this I am creating one temp table in which data is inserted and fetched during form load, here is the code

VB
Dim InDate As String
               Dim OutDate As String
               Dim DtIn As Date
               Dim DtOut As Date
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                        Regno = ds.Tables(0).Rows(i)(0).ToString()
                        barcode = ds.Tables(0).Rows(i)(1).ToString()
                        vehityp = ds.Tables(0).Rows(i)(2).ToString()
                        vehimodl = ds.Tables(0).Rows(i)(3).ToString()
                        InDate = ds.Tables(0).Rows(i)(4).ToString()
                        OutDate = ds.Tables(0).Rows(i)(5).ToString()
                        DtIn = DateTime.Parse(InDate)
                        DtOut = DateTime.Parse(OutDate)
                        diff = DtIn - DtOut
                        DiffD = diff.Days
                        DiffH = diff.Hours
                        DiffM = diff.Minutes
                        Try
                            sqlcmd = "Insert Into tmp ([RegistrationNo],[Barcode],[VehicleType],[VehicleModel] , [TranInDate], [TranOutDate], [OutDays], [OutHours], [OutMins]) Values ('" _
                            + Regno + "','" + barcode + "','" + vehityp + "','" + vehimodl + "', '" + InDate.ToString() + "', '" + OutDate.ToString() + "', " + DiffD.ToString() + ", " + DiffH.ToString() + ", " + DiffM.ToString() + ")"
                            cmd.CommandText = sqlcmd
                            cmd.ExecuteNonQuery()
                        Catch ex As Exception
                            MsgBox(ex.Message, "Messageinst")
                        End Try
                    Next


When My InDate is blank it is showing an error as
"String was not recognised as a valid DateTime"

Can anyone help me on how to insert the blank InDate value
Posted
Comments
Vedangi 11-Jul-12 4:19am    
which database you are using SQL Or Oracle ???

1 solution

This is not the most efficient way of passing parameters. Use parameterized queries, here is an example:

http://www.vb-helper.com/howto_net_db_parameterized_query.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900