没有合适的资源?快使用搜索试试~ 我知道了~
FileUpload上传图片保存到SQL数据库image字段
需积分: 30 9 下载量 114 浏览量
2018-06-18
21:43:32
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
2页
利用FileUpload上传图片后,保存到SQL数据库image字段
资源推荐
资源详情
资源评论
if (upImage.PostedFile != null)
{
string lName = upImage.PostedFile.FileName;
if (lName != "")
{
string tarPath = sysFunc.systemFound() + "FilesLib\\temp\\" + userID + "." + kzm;
upImage.PostedFile.SaveAs(tarPath);
try
{
opData.ExecuteSql(sysConst.SysteminfoCon, "delete from tFile_Img_Temp where userID=" + userID);
FileStream fs = new FileStream(tarPath, FileMode.Open); //文件流
byte[] xpIMG = new byte[fs.Length]; //设定字节流数组大小
BinaryReader br = new BinaryReader(fs); //读字节对象
xpIMG = br.ReadBytes(Convert.ToInt32(fs.Length));
br.Dispose();
fs.Dispose();
SqlConnection conn = new SqlConnection(sysConst.SysteminfoCon);
conn.Open();
String sqlcmd = "insert into tFile_Img_Temp (imgMain) values (@imgMain)";
SqlCommand CmdObj = new SqlCommand(sqlcmd, conn);
SqlParameter ImageMain = new SqlParameter();
ImageMain.ParameterName = "@imgMain";
ImageMain.SqlDbType = SqlDbType.Image;
ImageMain.Value = xpIMG;
{
string lName = upImage.PostedFile.FileName;
if (lName != "")
{
string tarPath = sysFunc.systemFound() + "FilesLib\\temp\\" + userID + "." + kzm;
upImage.PostedFile.SaveAs(tarPath);
try
{
opData.ExecuteSql(sysConst.SysteminfoCon, "delete from tFile_Img_Temp where userID=" + userID);
FileStream fs = new FileStream(tarPath, FileMode.Open); //文件流
byte[] xpIMG = new byte[fs.Length]; //设定字节流数组大小
BinaryReader br = new BinaryReader(fs); //读字节对象
xpIMG = br.ReadBytes(Convert.ToInt32(fs.Length));
br.Dispose();
fs.Dispose();
SqlConnection conn = new SqlConnection(sysConst.SysteminfoCon);
conn.Open();
String sqlcmd = "insert into tFile_Img_Temp (imgMain) values (@imgMain)";
SqlCommand CmdObj = new SqlCommand(sqlcmd, conn);
SqlParameter ImageMain = new SqlParameter();
ImageMain.ParameterName = "@imgMain";
ImageMain.SqlDbType = SqlDbType.Image;
ImageMain.Value = xpIMG;
资源评论
ztone2009
- 粉丝: 0
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功