如何在Asp.Net中将Varchar数据类型转换为日期时间数据类型 [英] How Do I Convert Varchar Data Type Into Datetime Data Type In Asp.Net

查看:117
本文介绍了如何在Asp.Net中将Varchar数据类型转换为日期时间数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net中将varchar数据类型转换为datetime数据类型,同时从table1更新我的table2





table1 < br $>


名称加入日期

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



table2



id name joindate

1 [null] [null](datetime)-datatype





i厌倦了使用eid = id join更新名称n日期。

名称已更新,但是当我使用加入日期时存放在table2。

显示错误。







请帮我解决这个问题以更新数据..

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..

推荐答案

规则之一的数据库:始终使用适当的数据类型。

和VARCHAR不适合存储日期的数据类型!



所以编辑哟你的Table1并将其更改为DateTime - 并重新加载所有数据以确保它是正确的,因为10/11/14可以读作dd / MM / yy,MM / dd / yy,yy / mm / dd或其他各种其他数据格式。这就是使用正确数据类型的重要原因!您通常知道何时插入数据的格式是什么,因为与用户交互的代码可以检查他的语言环境 - 但SQL不能!
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!


这篇关于如何在Asp.Net中将Varchar数据类型转换为日期时间数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆