Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatype to save excel file in sql server?

I have a table in which there are two 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 !

like image 569
user294636 Avatar asked Apr 27 '26 09:04

user294636


1 Answers

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();
like image 76
Jørn Schou-Rode Avatar answered Apr 30 '26 01:04

Jørn Schou-Rode