求高手给个上传图片的例子 怎么讲图片用二进制传到SQLSERVER,然后在窗体显示SQL中的二进制图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果一定要保存到SQL Server中,那么它是普通的BLOB类型数据,在内存中也就是byte[]。请查找有关内存中的数据跟图片的对应关系。请打好基础。 http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&tbo=d&q=%22sql+server%22+%E8%AF%BB%E5%86%99blob&btnG=Google+%E6%90%9C%E7%B4%A2http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&tbo=d&q=asp.net+%E8%BE%93%E5%87%BA%E5%9B%BE%E7%89%87&btnG=Google+%E6%90%9C%E7%B4%A2 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.IO;namespace PassMan{ public partial class Image : Form { public Image() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*jpg|*.jpg|*bmp|*.bmp|*gif|*.gif|*png|*.png"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string fullpath = openFileDialog1.FileName; FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read); byte[] imagebytes = new byte[fs.Length]; BinaryReader br = new BinaryReader(fs); imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));//把所选图片文件的流中的数据读入字节数组 SqlConnection conn = new SqlConnection("server=192.168.51.215;database=PassGL;uid=sa;pwd=123"); conn.Open(); SqlCommand cmd = new SqlCommand("insert into photos(photoid,photoimg,photoname) values(@id,@Image,@name)", conn); cmd.Parameters.Add("@id", SqlDbType.VarChar, 50); cmd.Parameters.Add("@Image", SqlDbType.Image); cmd.Parameters.Add("@name", SqlDbType.VarChar, 50); cmd.Parameters["@id"].Value = DateTime.Now.Year.ToString() + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond; cmd.Parameters["@Image"].Value = imagebytes; cmd.Parameters["@name"].Value = comboBox1.Text.ToString(); cmd.ExecuteNonQuery(); conn.Close(); MessageBox.Show("图片上传成功"); } } private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); try { using (SqlConnection conn = new SqlConnection("server=192.168.51.215;database=PassGL;uid=sa;pwd=123")) { SqlDataAdapter da = new SqlDataAdapter("SELECT photoimg FROM photos WHERE photoname='"+comboBox1.Text+"'", conn); da.Fill(dt); } } catch (Exception ex) { MessageBox.Show(ex.Message); } byte[] imagedata = (byte[])(dt.Rows[0][0]); MemoryStream myStream = new MemoryStream(); foreach (byte a in imagedata) { myStream.WriteByte(a); } Image myImage = Image.FromStream(myStream); myStream.Close(); this.pictureBox1.Image = myImage; this.pictureBox1.Refresh(); } }}错误 1 “PassMan.Image”并不包含“FromStream”的定义 E:\项目\密码工具\PassMan\Image.cs 69 35 PassMan错误 2 无法将类型“PassMan.Image”隐式转换为“System.Drawing.Image” E:\项目\密码工具\PassMan\Image.cs 71 38 PassMan请前辈帮忙看看什么原因,DLL的我都加载了,还提示这个错误! 看到发布会、有说SQL Server 2012版本可以直接存图片是真的么 C#编程 .NET Framework一般使用最新版吗? 急,急,急怎么让td中从数据库中获得的数据显示出红色??? winform 的显示html格式数据问题 使用.NET类库 对称加密 问题 .net compact framework编程求助! 急!急!急! 提示“Newline in constant”是什么问题 泛型使用问题 生成的静态HTML页面能不能像DataGrid一样分页?? 请教动态的给按钮指定单击事件? C#如何通过api获取其他程序listview控件各列的标题 执行处理时程序卡死,能否用异步处理,望指教… 关于Socket连接失败的问题???
http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&tbo=d&q=%22sql+server%22+%E8%AF%BB%E5%86%99blob&btnG=Google+%E6%90%9C%E7%B4%A2http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&tbo=d&q=asp.net+%E8%BE%93%E5%87%BA%E5%9B%BE%E7%89%87&btnG=Google+%E6%90%9C%E7%B4%A2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace PassMan
{
public partial class Image : Form
{
public Image()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*jpg|*.jpg|*bmp|*.bmp|*gif|*.gif|*png|*.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fullpath = openFileDialog1.FileName;
FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
byte[] imagebytes = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));//把所选图片文件的流中的数据读入字节数组 SqlConnection conn = new SqlConnection("server=192.168.51.215;database=PassGL;uid=sa;pwd=123");
conn.Open();
SqlCommand cmd = new SqlCommand("insert into photos(photoid,photoimg,photoname) values(@id,@Image,@name)", conn);
cmd.Parameters.Add("@id", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@Image", SqlDbType.Image);
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50);
cmd.Parameters["@id"].Value = DateTime.Now.Year.ToString() + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond;
cmd.Parameters["@Image"].Value = imagebytes;
cmd.Parameters["@name"].Value = comboBox1.Text.ToString();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("图片上传成功");
}
} private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
try
{
using (SqlConnection conn = new SqlConnection("server=192.168.51.215;database=PassGL;uid=sa;pwd=123"))
{
SqlDataAdapter da = new SqlDataAdapter("SELECT photoimg FROM photos WHERE photoname='"+comboBox1.Text+"'", conn);
da.Fill(dt);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
byte[] imagedata = (byte[])(dt.Rows[0][0]);
MemoryStream myStream = new MemoryStream();
foreach (byte a in imagedata)
{
myStream.WriteByte(a);
}
Image myImage = Image.FromStream(myStream);
myStream.Close();
this.pictureBox1.Image = myImage;
this.pictureBox1.Refresh();
}
}
}错误 1 “PassMan.Image”并不包含“FromStream”的定义 E:\项目\密码工具\PassMan\Image.cs 69 35 PassMan
错误 2 无法将类型“PassMan.Image”隐式转换为“System.Drawing.Image” E:\项目\密码工具\PassMan\Image.cs 71 38 PassMan请前辈帮忙看看什么原因,DLL的我都加载了,还提示这个错误!
是真的么