Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

pass datetime

I have a sub below. Date2 is not required. It can be blank sometimes because the data comes from a textbox. I can't just pass "" to this sub and store procedure. What should I do?


ALTER procedure [dbo].[InsertAppointments_tmp]

@ID      int,
@date1      smalldatetime,
@date2  smalldatetime,
@time1      varchar(12),
@time2  varchar(12)


as
insert into mytable(
ID,
date1,
date2,
time1,
time2)
values
(
@ID,
@date1,
@date2,
@time1,
@time2)                   






Public Sub load_appointment(ByVal id As Integer, _
                                    ByVal date1 As DateTime, ByVal date2 As DateTime, _
                                    ByVal date1_time As String, ByVal date2_time As String)
        Dim result As Integer = 0
        Using con As New SqlConnection(WebConfigurationManager.ConnectionStrings("mycon")
            Using sqlcmnd As New SqlCommand("mysp", con)
                sqlcmnd.CommandType = CommandType.StoredProcedure

                sqlcmnd.Parameters.AddWithValue("@id", id)
                sqlcmnd.Parameters.AddWithValue("@date1", date1)
                sqlcmnd.Parameters.AddWithValue("@date2", date2)
                sqlcmnd.Parameters.AddWithValue("@time1", date1_time)
                sqlcmnd.Parameters.AddWithValue("@time2", date2_time)

                con.Open()
                result = sqlcmnd.ExecuteNonQuery
                con.Close()
            End Using
        End Using
    End Sub
Avatar of c1nmo
c1nmo
Flag of United Kingdom of Great Britain and Northern Ireland image

Try DBNull.Value
Avatar of VBdotnet2005

ASKER

where should I put it?
Avatar of p_davis
p_davis

or make it datetime nullable
ASKER CERTIFIED SOLUTION
Avatar of c1nmo
c1nmo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial