date in web service

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barmatt80
    New Member
    • Dec 2007
    • 55

    date in web service

    I have a webservice that accepts a date which ultimately submits to a sql server 2008 database with a data type of date (allows null values), however the infopath form that submits that date sometimes might be blank or null.

    I can't figure out how to check if the date variable the web service is accepting (datStartDate) is blank or null from the form, and if null/blank then submit a Null value to the database, if not null send the date the form is sending.

    I have tried Nullable(Of Date) check on that variable and also hasvalue but can't get it to work.

    thanks for you help

    this is hte code i am currently using and works great if i actually submit a value

    Code:
    <WebMethod(Description:="")> _
        Public Function SubmitAppData(ByVal strAppID As String, ByVal datStartDate As Date) As Integer
    
            Dim sqlCon As New SqlConnection()
            Dim sqlCmd As New SqlCommand()
    
        
            'sqlCon.ConnectionString = "connection string info"
            sqlCon.ConnectionString = connStr
    
            If sqlCon.State = ConnectionState.Closed Then
                sqlCon.Open()
            End If
            sqlCmd.CommandText = "usp_SendValues"
            sqlCmd.Connection = sqlCon
            sqlCmd.CommandType = CommandType.StoredProcedure
    
            'Dim maxDate As Nullable(Of Date)
            'maxDate = datDRLastTestDate
    
            Dim Parameter1 As SqlParameter = New SqlParameter("@AppID", strAppID)
            Dim Parameter2 As SqlParameter = New SqlParameter("@StartDate", datStartDate)
    
            Parameter1.Direction = ParameterDirection.Input
            Parameter2.Direction = ParameterDirection.Output
    
            sqlCmd.Parameters.Add(Parameter0)
            sqlCmd.Parameters.Add(Parameter1)
    
    
            Dim dr As SqlDataReader
            dr = sqlCmd.ExecuteReader()
    
            sqlCon.Close()
    
    	Dim returnValue as String = "Hello"
    
            Return returnValue
    
        End Function
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I'm not entirely sure I understand what your problem is exactly...but..

    A DateTime is a primitive/value type which means that it always has a value. It can't be null/nothing.

    You can check to see if the DateTime contains the same value as a New DateTime to see if "nothing" was supplied. From this you can determine whether you parameter to DBNull.Value (if the user provided nothing) or to the date that the user provided.

    -Frinny

    Comment

    • barmatt80
      New Member
      • Dec 2007
      • 55

      #3
      thanks for the help i got it figured out, i changed it to text and was able to pass the null or date to the web service.

      Comment

      Working...