Click here to Skip to main content
12,254,021 members (66,419 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server , +
Hi,
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 10:07am
Edited 11-Nov-12 10:08am
v2

1 solution

Rate this: bad
 
good
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
Milind
  Permalink  
Comments
Xperment2008 12-Nov-12 10:49am
   
Hi,
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
Web02 | 2.8.160426.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2016
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