Click here to Skip to main content
12,757,882 members (38,357 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server , +
I am getting an annoying error while inserting into database. below is the query string. I get error on ExcecuteNOnQUery line. error is "Operand type clash: int is incompatible with date" below is the insert string.

Here User table has 4 columns. Date has date datatype and remaining are varchar(50)

sqlstring = "Insert Into User(Date,Phone_no,NameF,New_User) Values (" + Today.ToString("yy-MM-dd") + ",'" + txtPhoneno.Text + "','" + NameF.Text + "','" + N_User + "') "

Could anybody tell, what is happening wrong here.
Posted 11-Nov-12 11:07am
Updated 11-Nov-12 11:08am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What is today ? Is it a local variable defined? If you are trying to use DateTime then I believe it should be DateTime.Today.

Besides, this please note few points below.

Please notice that DateTime.Today will give only date part. If you need to store time as well then you should should DateTime.Now

Also, while inserting be aware of the datetime format of the sql.

And last point and the most important point: Rather than using direct inputs from the textbox, it is better to use parameterized query. As using direct textbox input in the query makes your system vulnerable to SQL Injection attack.

Hope that helps
Xperment2008 12-Nov-12 10:49am
I tried DateTime.Today but still I get same error. I am trying to input current date into table.
Milind Thakkar 12-Nov-12 12:56pm
What is the data type of "Date column?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100