//将SQL server2000中保存的图像显示在Picture中
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
byte[] buffByte = null;
string comm = @"select img from table1 where id = " + this.listBox1.SelectedValue ;
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand ();
this.sqlCommand1.CommandType = System.Data.CommandType.Text ;
this.sqlCommand1.CommandText = comm;
this.sqlCommand1.Connection = this.sqlConnection1 ;
this.sqlConnection1.Open();
System.Data.SqlClient.SqlDataReader rd = this.sqlCommand1.ExecuteReader();
while (rd.Read())
{
buffByte = ((byte[])rd[0]);
}
rd.Close();
this.sqlConnection1.Close();
//将图像的字节数组放入内存流
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffByte);
//通过流对象建立Bitmap
System.Drawing.Bitmap bmp = new Bitmap(ms);
this.pictureBox1.Image = bmp;
}
//将图像保存到SQL server2000的Image字段中
private void button2_Click_1(object sender, System.EventArgs e)
{
string pathName;
if (this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
pathName = this.openFileDialog1.FileName;
System.Drawing.Image img = System.Drawing.Image.FromFile(pathName);
this.pictureBox1.Image = img;
//将图像读入到字节数组
System.IO.FileStream fs = new System.IO.FileStream(pathName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] buffByte = new byte[fs.Length];
fs.Read(buffByte,0,(int)fs.Length);
fs.Close();
fs = null;
//建立Command命令
string comm = @"Insert into table1(img,name) values(@img,@name)";
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand ();
this.sqlCommand1.CommandType = System.Data.CommandType.Text ;
this.sqlCommand1.CommandText = comm;
this.sqlCommand1.Connection = this.sqlConnection1 ;
//创建Parameter
this.sqlCommand1.Parameters.Add("@img",System.Data.SqlDbType.Image);
this.sqlCommand1.Parameters[0].Value = buffByte;
this.sqlCommand1.Parameters.Add("@name",System.Data.SqlDbType.VarChar);
this.sqlCommand1.Parameters[1].Value =pathName.Substring(pathName.LastIndexOf("\\")+1);
try
{
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteNonQuery();
this.sqlConnection1.Close();
}
catch(System.Exception ee)
{
MessageBox.Show(ee.Message );
}
buffByte = null;
this.FillListBox();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
java毕业设计,项目包含完整前后端源码,带数据库sql文件。项目可正常运行! 环境说明: 开发语言:Java 前端框架:小程序 JDK版本:JDK1.8 数据库:mysql 5.7+ 部署容器:tomcat7+ 数据库工具:Navicat11+ 开发软件:eclipse/myeclipse/idea(推荐idea) Maven包:Maven3.3.9
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计之《Java 程序设计》课程网上辅助教学系统的设计与实现web源码.zip (355个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
index.css 227KB
index.css 227KB
index.css 227KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
font-awesome.css 28KB
font-awesome.css 28KB
font-awesome.css 26KB
quill.snow.css 24KB
swiper.min.css 13KB
swiper.min.css 13KB
nav.css 2KB
my.css 1KB
my.css 1KB
my.css 1KB
index.css 480B
index.css 480B
common.css 476B
notice.css 475B
notice.css 475B
fontawesome-webfont.eot 55KB
fontawesome-webfont.eot 55KB
fontawesome-webfont.eot 55KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
my.log.2021-03-27.0.gz 6KB
zuoyeInfo.html 43KB
zuoyeInfo.html 43KB
fileInfo.html 22KB
fileInfo.html 22KB
teacherInfo.html 20KB
teacherInfo.html 20KB
adminInfo.html 20KB
adminInfo.html 20KB
userInfo.html 20KB
userInfo.html 20KB
nxTestpaperInfo.html 20KB
nxTestpaperInfo.html 20KB
nxQuestionInfo.html 20KB
nxQuestionInfo.html 20KB
advertiserInfo.html 18KB
advertiserInfo.html 18KB
nxTypeInfo.html 18KB
nxTypeInfo.html 18KB
nxQuestionTypeInfo.html 18KB
nxQuestionTypeInfo.html 18KB
zuoyeInfoComment.html 16KB
zuoyeInfoComment.html 16KB
fileInfoComment.html 16KB
fileInfoComment.html 16KB
zuoyeInfoDetail.html 14KB
fileInfoDetail.html 14KB
fileInfoDetail.html 14KB
nxExamineInfo.html 13KB
nxExamineInfo.html 13KB
nxScoreInfo.html 13KB
nxScoreInfo.html 13KB
nxMarkPaper.html 12KB
nxMarkPaper.html 12KB
accountTeacherInfo.html 11KB
accountTeacherInfo.html 11KB
accountAdminInfo.html 11KB
accountAdminInfo.html 11KB
accountUserInfo.html 11KB
accountUserInfo.html 11KB
index.html 11KB
index.html 11KB
fileInfo.html 11KB
fileInfo.html 11KB
updatePassword.html 10KB
updatePassword.html 10KB
zuoyeInfo.html 10KB
index.html 10KB
advertiserInfo.html 7KB
advertiserInfo.html 7KB
register.html 5KB
register.html 5KB
login.html 5KB
login.html 5KB
index.html 0B
zuoyeInfoDetail.html 0B
zuoyeInfo.html 0B
kechengwangshang.iml 8KB
NxTestpaperInfoService.java 16KB
AccountController.java 9KB
ZuoyeInfoController.java 9KB
EchartsController.java 6KB
NxSystemFileController.java 6KB
MenuController.java 6KB
TeacherInfoController.java 5KB
AdminInfoController.java 5KB
UserInfoController.java 5KB
NxTestpaperInfoController.java 4KB
NxQuestionTypeInfoController.java 4KB
AdvertiserInfoController.java 4KB
NxQuestionInfoController.java 4KB
共 355 条
- 1
- 2
- 3
- 4
资源评论
大学生资源网
- 粉丝: 131
- 资源: 1334
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功