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 6071521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:03:24+00:00 2026-05-23T10:03:24+00:00

I used to query: Dim a As String a = INSERT INTO tblVisitor(Name, Sex,

  • 0

I used to query:

Dim a As String
a = "INSERT INTO tblVisitor(Name, Sex, TimeIn, EnterDate)
     VALUES('"& txtName.Text &"', '"& cboSex.Text &"', '"& Now() &"', '"& DateTime.Parse(cboEnterDate.Text) &"')"

myCommand = New SqlCommand(a, myConnection)
myCommand.ExecuteNonQuery()
........................................

Which cboEnterDate is my DateTime Picker. Then I got the message:

Conversion failed when converting date time from character string.

Please 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-23T10:03:24+00:00Added an answer on May 23, 2026 at 10:03 am

    By constructing a string, you a) open yourself to SQL injection, and b) end up converting strings to datetimes to strings to datetimes.

    If, instead, you use parameters:

    Dim a As String
    a = "INSERT INTO tblVisitor(Name, Sex, TimeIn, EnterDate)
         VALUES(@Name, @Sex, @TimeIn, @EnterDate)"
    
    myCommand = New SqlCommand(a, myConnection)
    myCommand.Parameters.AddWithValue("@Name",txtName.Text)
    myCommand.Parameters.AddWithValue("@Sex",cboSex.Text)
    myCommand.Parameters.AddWithValue("@TimeIn",DateTime.Now)
    myCommand.Parameters.AddWithValue("@EnterDate",DateTime.Parse(cboEnterDate.Text))
    myCommand.ExecuteNonQuery()
    

    Which only performs a single conversion of string to datetime. Although, if cboEnterDate is a DateTimePicker, you can avoid treating it as a string at all:

    myCommand.Parameters.AddWithValue("@EnterDate",cboEnterDate.Value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the query: INSERT INTO `users` (username, password, email) VALUES ('testu', 'testp', 'teste')
To query an excel sheet via SQL, I used to use either: Dim excelConnectionString
Last time I used two parameter to query & show report. It worked well.
I am trying to speed up an often used query. Using a CompiledQuery seemed
I used a query a few weeks ago in MySQL that described a table
I have a search form used to query service provisions, which I will call
I'm having problems with an SQL query used to display custom profile fields and
Once, I used this query to select the number of items in order to
I have a stored procedure that consists of a single select query used to
Following query is used for Getting Categories and one news for each category. How

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.