varbinarymax

How do I insert/retrieve Excel files to varbinary(max) column in SQL Server 2008?

跟風遠走 提交于 2019-11-30 09:24:13
I'm trying to save Excel files into the database, I do not want to use filestream as it is required to have a server for that. So how do I insert/update/select into the table that has a column of type varbinary(max) ? If you want to do it in straight ADO.NET, and your Excel files aren't too big so that they can fit into memory at once, you could use these two methods: // store Excel sheet (or any file for that matter) into a SQL Server table public void StoreExcelToDatabase(string excelFileName) { // if file doesn't exist --> terminate (you might want to show a message box or something) if (

How do I insert/retrieve Excel files to varbinary(max) column in SQL Server 2008?

左心房为你撑大大i 提交于 2019-11-29 14:29:52
问题 I'm trying to save Excel files into the database, I do not want to use filestream as it is required to have a server for that. So how do I insert/update/select into the table that has a column of type varbinary(max) ? 回答1: If you want to do it in straight ADO.NET, and your Excel files aren't too big so that they can fit into memory at once, you could use these two methods: // store Excel sheet (or any file for that matter) into a SQL Server table public void StoreExcelToDatabase(string

Retrieve varbinary(MAX) from SQL Server to byte[] in C#

本秂侑毒 提交于 2019-11-29 13:27:07
I'm trying to get a varbinary(MAX) from SQL Server to a byte[] variable in C#. How can I do this? Thanks private static byte[] getDocument(int documentId) { using (SqlConnection cn = new SqlConnection("...")) using (SqlCommand cm = cn.CreateCommand()) { cm.CommandText = @" SELECT DocumentData FROM Document WHERE DocumentId = @Id"; cm.Parameters.AddWithValue("@Id", documentId); cn.Open(); return cm.ExecuteScalar() as byte[]; } } You have to SELECT DATALENGTH(data) and data where data is your varbinary(max) int i=0; long dataLen = dr.GetInt64(i++); if (dataLen > 0) { Data = new byte[dataLen]; dr

Retrieve varbinary(MAX) from SQL Server to byte[] in C#

旧巷老猫 提交于 2019-11-28 07:17:49
问题 I'm trying to get a varbinary(MAX) from SQL Server to a byte[] variable in C#. How can I do this? Thanks 回答1: private static byte[] getDocument(int documentId) { using (SqlConnection cn = new SqlConnection("...")) using (SqlCommand cm = cn.CreateCommand()) { cm.CommandText = @" SELECT DocumentData FROM Document WHERE DocumentId = @Id"; cm.Parameters.AddWithValue("@Id", documentId); cn.Open(); return cm.ExecuteScalar() as byte[]; } } 回答2: You have to SELECT DATALENGTH(data) and data where data