代码如下:
String constr="data source=zss;initial catalog=ZssTest;
password=norman;persist security info=True;user id=sa;
workstation id=ZSS;packet size=4096";
SqlConnection sqlcon=new SqlConnection(constr);
String sqlselect="select bin_image,id from Table_1 where id='29'";
SqlCommand sqlcom=new SqlCommand(sqlselect,sqlcon);
sqlcon.Open();
SSqlDataReader reader=sqlcom.ExecuteReader();
reader.Read();
//取出数据
Byte[] bytes=(Byte[])reader["bin_image"];
//根据生成Bitmap
System.IO.MemoryStream ms=new System.IO.MemoryStream(bytes,0,bytes.
Length);
Bitmap bitmap=new Bitmap(ms,true);
//在窗口上绘制image
Graphics g=Graphics.FromHwnd(this.Handle);
g.DrawImage(bitmap,10,10,bitmap.Width,bitmap.Height);
sqlcon.Close();
String constr="data source=zss;initial catalog=ZssTest;
password=norman;persist security info=True;user id=sa;
workstation id=ZSS;packet size=4096";
SqlConnection sqlcon=new SqlConnection(constr);
String sqlselect="select bin_image,id from Table_1 where id='29'";
SqlCommand sqlcom=new SqlCommand(sqlselect,sqlcon);
sqlcon.Open();
SSqlDataReader reader=sqlcom.ExecuteReader();
reader.Read();
//取出数据
Byte[] bytes=(Byte[])reader["bin_image"];
//根据生成Bitmap
System.IO.MemoryStream ms=new System.IO.MemoryStream(bytes,0,bytes.
Length);
Bitmap bitmap=new Bitmap(ms,true);
//在窗口上绘制image
Graphics g=Graphics.FromHwnd(this.Handle);
g.DrawImage(bitmap,10,10,bitmap.Width,bitmap.Height);
sqlcon.Close();
解决方案 »
- 向 Silverlight 发送键盘按键消息
- 根据规则自动生成编码
- 请教匿名方法 与命名方法 实现委托有什么区别?分别有什么好处?
- [求助]在winform的datagrid里我添加了其他控件,但在datagrid里的cell里必须电击鼠标两次才能让控件获得焦点,急急
- 画实时曲线
- 套接字编程问题
- 大侠们帮个忙!
- 不明白!HTML和WEB窗体都有image及其他相同的控件,问他们能实现相同的功能吗?有区别吗?
- 极度困惑中~~~
- 用C#写的WebForm程序能否编译,我的目的是不让别人看不到源代码,还有其他方法吗 ?
- VS.net的文档错了还是我错了??请各位帮忙看看
- 中国队第一场(对哥斯达黎加)输0:2,灌水啊~~~~
Byte[] bytes=(Byte[])reader["bin_image"];
报告说,不能实现转换。
SqlCommand sqlCommand=new SqlCommand("select id,name,age,image from students",this.sqlConnection1);
SqlDataReader sqlDataReader=sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
sqlDataReader.Read();
textBoxId.Text=sqlDataReader.GetInt32(0).ToString();
textBoxName.Text=sqlDataReader.GetString(1);
textBoxAge.Text=sqlDataReader.GetInt32(2).ToString();
int bufferSize=100;
long alreadReadSize=0;
int readingSize;
byte[] imageFieldValue=new byte[bufferSize];
MemoryStream memoryStream=new MemoryStream();
do{
readingSize=(int)sqlDataReader.GetBytes(3,alreadReadSize,imageFieldValue,0,bufferSize);
memoryStream.Write(imageFieldValue,0,readingSize);
alreadReadSize+=readingSize;
}
while (readingSize==bufferSize);
pictureBoxImage.Image=new Bitmap(memoryStream);
sqlDataReader.Close();
this.sqlConnection1.Close();
}
绝对好,昨晚才编的?解决问题别忘了给分