开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 3043|回复: 0

[求助] c#上传pdf文件

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
10
软币
108
在线时间
6 小时
注册时间
2019-4-22
发表于 2019-4-24 11:15:28 | 显示全部楼层 |阅读模式
本帖最后由 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();





下载附件



其中ShijuanContent数据类型是ntext,上传pdf文件时,出现不兼容问题


回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-6-6 05:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表