Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to convert varchar data type into datetime data type in asp.net while updating my table2 from table1


table1

eid name joiningdate
1 abc 10/11/14(varchar(20) -datatype

table2

id name joiningdate
1 [null] [null] (datetime)-datatype


i tired to update name n date using eid=id join .
name was geting updated but when i used joining date to store in table2 .
it was showing error.



kindly help me with this problem to update the data..
Posted
Comments
Wombaticus 24-Jul-14 5:33am    
I am not clear what ASP.NET has to do with this, as you seem to be implying you are trying to do this via a SQL statement? I suggest you look at the CAST and CONVERT functions in SQL
10923679 24-Jul-14 5:37am    
okay ..

thanks
10923679 24-Jul-14 5:39am    
well i have two table.
both have different datatype and filled with values
i want to update my table2 with the help of table1 using asp.net
normal update fromone table to another. (filling the null values)
but becos dates have different datatype so i am not to update it

1 solution

Rule one of databases: always use the appropriate datatype.
And VARCHAR is not an appropriate datatype for storing dates!

So edit your Table1 and change it to DateTime - and reload all the data to make sure it's correct, because 10/11/14 can be read as dd/MM/yy, MM/dd/yy, yy/mm/dd, or various other formats. This is why it's important to use the right datatype! You generally know when you are inserting the data what format it is, because your code that interacts with the user can check on his locale - but SQL can't!
 
Share this answer
 
Comments
10923679 24-Jul-14 6:27am    
okay. thank you so much ..

i will try to do edit table1.

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