c#上传pdf文件
本帖最后由 shanghan 于 2019-4-24 11:20 编辑代码如下 : FileStream fs = new FileStream(this.tbFilenameFull.Text, FileMode.Open);
//二进制形式读取
BinaryReader br = new BinaryReader(fs);
//将文件内容读入到字节数组byData中
Byte[] byData = br.ReadBytes((int)fs.Length);
fs.Close();
//获取文档类型//插入文档的sql字符串
string sqlStr = "insert into tb_Shijuan(ShijuanName,ShijuanTime,Remark,ShijuanContent) " +
"values('" + tbFileName.Text + "',@DocumentTime,'"+ rtxRemark.Text + "',@file)";
//从db获取数据库连接
SqlConnection myconn = db.Conn;
myconn.Open();
//根据sql语句建立sql命令
SqlCommand mycomm = new SqlCommand(sqlStr, myconn);
//设置命令参数
mycomm.Parameters.Add("@file", SqlDbType.Binary, byData.Length);
mycomm.Parameters.Add("@DocumentTime", SqlDbType.DateTime);
mycomm.Parameters["@file"].Value = byData;
mycomm.Parameters["@DocumentTime"].Value = DateTime.Now.ToString();
http://www.dxper.net/data/attachment/forum/201904/24/111246ao7oorux3sxc3uy0.png
下载附件
其中ShijuanContent数据类型是ntext,上传pdf文件时,出现不兼容问题
页:
[1]