SQLServer与MySQL在C#中数据类型对应的区别
- 现在是使用SQLServer数据库进行开发,由于以前是使用的MySQL数据库,导致在项目开发中报错有些摸不着头脑,借此记录下来
前提:C#开发
- 数据类型对应
tinyint ——> int //MySQL
tinyint——> int //SQLServer 报错类型转换异常 需声明为byte
- 值范围异常
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value
//将datetime2数据类型转换为datetime数据类型导致值超出范围
- datetime 的范围是:1753-01-01 00:00:00 到 9999-12-31 23:59:59.997
- datetime2 的范围是:0001-01-01 00:00:00 到 9999-12-31 23:59:59.9999999
- 声明Model类型为DateTime类型,使用Postman调试接口时,时间类型属性的值默认0001-01-01 00:00:00,而SQLServer中该字段类型为datetime类型,所以抛出异常
- 所以在开发过程中要注意下细节哟~