如何将文件插入到文件stream数据types
我正在创build一个应用程序,使用SQL Server 2008提供的文件stream数据types将Excel文件存储到数据库,现在我坚持在Internet上search最佳实践方式,使用C#存储过程插入它。
到目前为止,我已经创build了数据库结构和类,我现在需要做的是实际使用存储过程,我卡住了,下面是代码片段
OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowDialog(); if (ofd.CheckFileExists) { .... } using (SqlConnection conn = new SqlConnection(Murel.Util.DBUtil.CONSTRING)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand("items_insert", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@name", "test")); cmd.Parameters.Add(new SqlParameter("@template", HELP)); Guid id = (Guid)cmd.ExecuteScalar(); return true; } } catch (Exception ex) { throw ex; } finally { conn.Close(); } }
数据表由一个唯一标识符的id
, varbinary(max)
名称和模板组成,我已经有了其他的东西,我只需要知道要放什么
cmd.Parameters.Add(new SqlParameter("@template", HELP));
谢谢,
大stream士
尝试这个,这应该工作
byte[] fileContent = new byte[ofd.PostedFile.ContentLength]; ofd.PostedFile.InputStream.Read(fileContent, 0,ofd.PostedFile.ContentLength); command.Parameters.Add("@FileContent", SqlDbType.VarBinary, -1).Value = fileContent;
ofd是你的FileUpload控件
- 导出为excel数据时出错:“',hex值0x07,是一个无效的字符,使用c#
- 有没有Aspose的方式获取文本,包括换行符/回车,Excel中的单元格?
- (object )range.get_Value(XL.XlRangeValueDataType.xlRangeValueDefault)导致转换错误
- Excel VSTOsorting对话框C#
- 使用c#从excel文件中删除行
- closuresExcel数据透视表小计VB.NET
- 如何使用VB.net保留公式并清除Excel中的内容?
- 在.Net的Excel文档中查找最右边的单元格
- Interop:无法调用get_Range,也不能使用Range()返回的二维对象数组。