Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:33:44+00:00 2026-05-29T06:33:44+00:00

I have a web app with a form that I am trying to pass

  • 0

I have a web app with a form that I am trying to pass to an ASP.NET server (using VB.NET) and then on to a MS SQL Server table. The form uses a jQuery datepicker in several textboxes and formats them as MM/dd/yyyy. The form fields are then passed through a PageMethod to the web server which takes the various field values and combines them into a SQL UPDATE command.

I am constantly getting the following error whenever I try to execute the SQL command:

Conversion failed when converting date and/or time from character string.

Here is the code on the server:

Using myConn As New System.Data.SqlClient.SqlConnection(CString.ConnectionString)
    myConn.Open()

    Dim cmd As New System.Data.SqlClient.SqlCommand("UPDATE table " & _
                             "SET type = '" & type & "', " & _ 
                                 "target = '" & "@target" & "', " & _
                                 "patient = '" & patient & "', " & _
                                 "dob = '" & "@dob" & "' " & _   
                             "WHERE serial = '" & serial & "'", myConn)


    cmd.Parameters.Add(SqlParameter("@target", Data.SqlDbType.Date))       
    cmd.Parameters.Add(SqlParameter("@dob", Data.SqlDbType.Date))

    If target = "" Then
        cmd.Parameters("@target").Value = Data.SqlTypes.SqlDateTime.Null
    Else
        cmd.Parameters("@target").Value = target
    End If

    If dob = "" Then
        cmd.Parameters("@dob").Value = Data.SqlTypes.SqlDateTime.Null
    Else
        cmd.Parameters("@dob").Value = dob
    End If

    cmd.ExecuteNonQuery()

End Using

Note: I’ve tried about twenty different ways of parsing the dates, converting them to dates, changing around the formats and none of it has worked.

Note 2: The conditional statements at the end are simply to prevent empty date fields from being stored in the SQL DB as “1/1/1900”, but rather as an actual SQL NULL value. From debugging though, it seems that this is not the issue – it is when there is an actual value that the error is fired.

If anyone can see what I’m doing wrong and how I might fix it, it would be greatly appreciated. Thanks in advance for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:33:44+00:00Added an answer on May 29, 2026 at 6:33 am

    You are mixing up your parameterized and non-parameterized parts (why aren’t you parameterizing everything?)

    Dim cmd As New System.Data.SqlClient.SqlCommand("UPDATE table " & _
                             "SET type = '" & type & "', " & _ 
                                 "target = @target, " & _
                                 "patient = '" & patient & "', " & _
                                 "dob = @dob " & _   
                             "WHERE serial = '" & serial & "'", myConn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a web app using Dojo. I have a form that
So I have an asp.net Web Application (Not Web Site) that I am trying
I have a web app which connects to a server using a TCP connection
I have a web app built against asp.net 2.0, but keep getting the following
I have a PHP-based web app that I'm trying to apply Apache's mod_rewrite to.
I have a web app. I'm trying to disable/prevent the scrolling that occurs when
I'm developing a web app where i have a form like that <form name=form
I am trying to make a simple web app. I have a User table
I have a simple web app: a web page with a form to submit,
I use sitemesh for page decoration in my web app. I have a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.