开发者

Datatype to save excel file in sql server?

I have a table in which there are two开发者_StackOverflow columns : 1. import type, 2. Excel import template.

The second column - "Excel import template" should store the whole excel file.

How would I save excel file in databse...can I use binary datatype column, convert excel file to bytes and save the same ?

Thanks in advance !


Yes, you can use a binary file type. VARBINARY(MAX) is likely to fit the purpose best.

Regarding how to "convert the Excel file to bytes" (it really is bytes from the beginning), we will need to know more about your programming environment in order to help. If you are using .NET, you should be able to do something like this:

var insert = new SqlCommand("INSERT INTO tbl (xls) VALUES (@xls)", conn);
insert.Parameters.AddWithValue("xls", File.ReadAllBytes("template.xls"));
insert.ExecuteNonQuery();


varbinary(max)

An Excel file is binary so you can't use characters like varchar(max)

And you can't use IMAGE because it's deprecated as MSDN says


Excel does support saving to XML. You could use this and store the sheet in an XML datacolumn, or a varchar(max)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜