VBdotnet2005
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(WebConfigura tionManage r.Connecti onStrings( "mycon")
Using sqlcmnd As New SqlCommand("mysp", con)
sqlcmnd.CommandType = CommandType.StoredProcedur e
sqlcmnd.Parameters.AddWith Value("@id ", id)
sqlcmnd.Parameters.AddWith Value("@da te1", date1)
sqlcmnd.Parameters.AddWith Value("@da te2", date2)
sqlcmnd.Parameters.AddWith Value("@ti me1", date1_time)
sqlcmnd.Parameters.AddWith Value("@ti me2", date2_time)
con.Open()
result = sqlcmnd.ExecuteNonQuery
con.Close()
End Using
End Using
End Sub
ALTER procedure [dbo].[InsertAppointments_
@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(WebConfigura
Using sqlcmnd As New SqlCommand("mysp", con)
sqlcmnd.CommandType = CommandType.StoredProcedur
sqlcmnd.Parameters.AddWith
sqlcmnd.Parameters.AddWith
sqlcmnd.Parameters.AddWith
sqlcmnd.Parameters.AddWith
sqlcmnd.Parameters.AddWith
con.Open()
result = sqlcmnd.ExecuteNonQuery
con.Close()
End Using
End Using
End Sub
Try DBNull.Value
ASKER
where should I put it?
or make it datetime nullable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.