数据转换成在asp.net中一些奇怪的数据 [英] Data is converting into some weird data in asp.net
本文介绍了数据转换成在asp.net中一些奇怪的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Excel上传到数据库,在数据库中创建一个类型
然后所有的数据插入到另一个表。
例如:
CREATE TYPE [DBO]。[temp_tbl_vendor]如表([报价商家code] [VARCHAR(10)NULL,
[BillDt] [VARCHAR(12)NULL)创建PROC myproc_bulkinsert
(@venid INT,@temptable temp_tbl_vendor只读)
如
开始
插入从temp_tbl_vendor mynewtab SELECT *
结束
一切工作正常只是问题是,Excel数据就是 20150702
正在改变 2.01507e002
。
解决方案
有几个在你的设计问题。
- 从不存储日期作为在数据库中的字符串。日期是日期,并应被存储在日期时间字段。
修改 temp_tbl_vendor 的以
CREATE TYPE [DBO]。[temp_tbl_vendor]如表([报价商家code] [VARCHAR(10)NULL,
[BillDt] DATETIME NULL)
在
更改相应列的的 mynewtab 的到 DATETIME
字段
I am uploading from Excel into database by creating type in the database and then inserting all the data into another table.
For example:
CREATE TYPE [dbo].[temp_tbl_vendor] AS TABLE([VendorCode] [varchar](10) NULL,
[BillDt] [varchar](12) NULL )
create proc myproc_bulkinsert
(@venid int, @temptable temp_tbl_vendor readonly)
as
begin
insert into mynewtab select *from temp_tbl_vendor
end
Everything is working fine only the problem is that Excel data that is 20150702
is changing to 2.01507e002
.
解决方案
There are couple of issues in your design.
- Never store date as a string in the database. Date is a date and should be stored in a DateTime field.
Change temp_tbl_vendor to:
CREATE TYPE [dbo].[temp_tbl_vendor] AS TABLE([VendorCode] [varchar](10) NULL,
[BillDt] DATETIME NULL )
Change corresponding column in mynewtab to a DATETIME
field
- You need to convert spreadsheet column to a date type and/or more importantly read it into a date field before inserting into the temp_tbl_vendor.
这篇关于数据转换成在asp.net中一些奇怪的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文