//将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 程序设计》课程网上辅助教学系统的设计与实现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
资源评论
码农落落
- 粉丝: 543
- 资源: 2304
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- pcb原理图.PcbDoc
- 计算机视觉-人脸识别-开发包-商业应用-人脸识别开发包(免费,可商用,有演示、范例、说明书)完整项目实例源码.zip
- Libraries-Comm-Controller
- 豆瓣电影爬虫 爬取top电影的评论 + 每个用户的看过的电影的评论 用于推荐系统的 协同过滤+源代码+文档说明
- 交互设计课程竞品分析内容案例设计
- c07c4b30caf2ab290c3f2eea8339b34b.mp4
- emqx服务器搭建文件
- Libraries-Comm-Controller-DOC-V2-0-1-en.pdf
- update9-20240601.5.205.slice.img.7z.003
- 9f9ae03ea06c5c991afa26c5813d8831.amr
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功