如何直接根据网页图片路径,上传图片二进制流到数据库 rt 这是最好的方案不行的话 根据图片名称上传也行 不要用fileupload控件 我这是后台程序 不需要人工添加帮帮忙!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/phone/archive/2010/09/14/1825850.html 你既然知道连接,那么可以webclient先下载,然后将数据流提交到数据库(http://www.cnblogs.com/tuyile006/archive/2007/01/08/614718.html) 发错了 是二楼 4楼public void imgToDB(string sql) { //参数sql中要求保存的imge变量名称为@images //调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo='" + temp + "'"); FileStream fs = File.OpenRead(t_photo.Text); byte[] imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); SqlCommand com3 = new SqlCommand (sql,con); com3.Parameters.Add("@images", SqlDbType.Image).Value = imageb; if (com3.Connection.State == ConnectionState.Closed) com3.Connection.Open(); try { com3.ExecuteNonQuery(); } catch { } finally { com3.Connection.Close(); } } imge变量 是路径么 以解决了 不过用的是本地文件夹路径 网页图片路径的话 应该是差不多的 String filepath; filepath = "F:\\SLmanager\\Web\\picture\\" + rename + ".png"; FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); //利用新传来的路径实例化一个FileStream对象 int filelength = Convert.ToInt32(fs.Length); string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1); //文件名不带后缀名(后面也没有用到<可删>) string name = filename.Substring(0, filename.Length - 4); byte[] sf = new byte[filelength]; //定义byte型数组 webhandler什么意思,还有.ashx文件 三层结构购物车 asp.net fck上传的文件按年月日分类~ aspnet gridview 主键设置与获取 DataKeys 如何将一字符串转换成XslCompiledTransform对象 日期处理 在ASP。NET中插入SQL语句,怎么写才能不乱呢?“”‘’怎么用呀! 发送多个参数 CMS建站 求助:进度条 JQuery 调用后台方法 失败 【急】如何在aspx.cs页面使用confirm,并返回值?
4楼public void imgToDB(string sql)
{ //参数sql中要求保存的imge变量名称为@images
//调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo='" + temp + "'");
FileStream fs = File.OpenRead(t_photo.Text);
byte[] imageb = new byte[fs.Length];
fs.Read(imageb, 0, imageb.Length);
fs.Close();
SqlCommand com3 = new SqlCommand (sql,con);
com3.Parameters.Add("@images", SqlDbType.Image).Value = imageb;
if (com3.Connection.State == ConnectionState.Closed)
com3.Connection.Open();
try
{
com3.ExecuteNonQuery();
}
catch
{ }
finally
{ com3.Connection.Close(); }
}
imge变量 是路径么
String filepath;
filepath = "F:\\SLmanager\\Web\\picture\\" + rename + ".png";
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
//利用新传来的路径实例化一个FileStream对象
int filelength = Convert.ToInt32(fs.Length);
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
//文件名不带后缀名(后面也没有用到<可删>)
string name = filename.Substring(0, filename.Length - 4);
byte[] sf = new byte[filelength]; //定义byte型数组