Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
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
Updated 11-Nov-12 10:08am
v2

1 solution

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
 
Share this answer
 
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.
MT_ 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900