c# winform数据库中存储图片是二进制的,现在却不能在datagridview中显示出来,求高手支招。

c# winform数据库中存储图片是二进制的,现在却不能在datagridview中显示出来,求高手支招。,第1张

那个老师教你用datagridview显示!用pictureBox不是更好吗?我给你一段源程序!你好好看看!数据库我也给你!只是!

源代码如下:

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemText;

using SystemWindowsForms;

using SystemDataSqlClient;

using SystemIO;

using SystemDataSqlTypes;

namespace BLOB

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

UpdateTimeText = SystemDateTimeNowToString();

}

string PhotoName = "";

byte[] Pic;

private void BSelect_Click(object sender, EventArgs e)

{

openFileDialog1Filter = "选择(BMP;JPG;GIF)|BMP;JPG;GIF|All files()|";

if (openFileDialog1ShowDialog() == DialogResultOK)

{

pictureBox1Image = ImageFromFile(openFileDialog1FileName,true);//牛逼啊、、、、、、、、、、、、

PhotoName = openFileDialog1FileName;

PnameText = PhotoNameSubstring(PhotoNameLastIndexOf(@"\") + 1);//;;;;;;;;;;;;;;;;;;;1·11!!

}

else

{

MessageBoxShow("您还未选取", "提示", MessageBoxButtonsOK, MessageBoxIconInformation);

return;

}

}

private void BAdd_Click(object sender, EventArgs e)

{

SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=Contact;Integrated Security=True");

try

{

connOpen();

SqlCommand cmd = new SqlCommand("insert into BLOB values(@name,@time,@photo)", conn);

cmdParametersAddWithValue("@name", PnameText);

cmdParametersAddWithValue("@time", UpdateTimeText);

Pic = FileReadAllBytes(PhotoName);

cmdParametersAddWithValue("@photo", Pic);

cmdExecuteNonQuery();

connClose();

MessageBoxShow("插入数据成功!", "提示:", MessageBoxButtonsOKCancel, MessageBoxIconInformation);

}

catch (Exception ex)

{

MessageBoxShow(exToString());

}

}

private void Form1_Load(object sender, EventArgs e)

{

SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=Contact;Integrated Security=True");

if (connState == ConnectionStateClosed)

{

connOpen();

}

SqlCommand cmd = new SqlCommand("select name from BLOB",conn);

SqlDataReader dr = cmdExecuteReader();

while (drRead())

{

listItemsAdd(drGetString(0));

}

}

private void list_SelectedIndexChanged(object sender, EventArgs e)

{

if (listSelectedIndex == -1)

{

return;

}

else

{

SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=Contact;Integrated Security=True");

if (connState == ConnectionStateClosed)

{

connOpen();

}

string SelectItem = listSelectedItemToString();

SqlCommand cmd = new SqlCommand("Select  from BLOB where name=@SelectItems",conn);

cmdParametersAddWithValue("@SelectItems", SelectItem);

SqlDataReader dr = cmdExecuteReader();

if (drRead())

{

PnameText = drGetString(0);

UpdateTimeText = drGetDateTime(1)ToString();

SqlBytes PhotoBytes = drGetSqlBytes(2);

pictureBox1Image = ImageFromStream(PhotoBytesStream);

}

drClose();

connClose();  //最好加上这两个CLOSE()方法!

}

}

}

}

数据库 和 C#  自己区分!我想你能看懂:

用表达之判断<img></img>之间的就是没有的就是文字了。

也可以用jQuery获取文章内

把文章内容用放入一个层中随便取个名字这里叫con

class用 id用# 新建个层用来存放获取的地址叫add

#con con

$()ready(function(){

var img_con;

img_con=$("#con img");

$("add")html(img_con);

}

);

img_con为所有地址

<div class="add">读取的内容</div>

照你上边的原文:有几个地方是存在点问题。

1、where expect='"&qihao&"' and ' and 之前应该有空格。

2、protype like 'fsd' ' 如果fsd是个变量,则应写成 protype like '%"&fsd&"%'

3、rsopen sql,conn,1,1 ' 这么写更好一些。

其它没发现什么。

1、准备要显示的,并创建一个最简单的jsp页面,运行起来。

2、通过ImageIo读取。

3、将图像的元字节数据保存到bytearray中。

4、将图像的字节数据用base64编码,转换成base64字符串。

5、把base64编码过的字符串放到img元素的src属性上。

6、最后就可以看到效果了。

以上就是关于c# winform数据库中存储图片是二进制的,现在却不能在datagridview中显示出来,求高手支招。全部的内容,包括:c# winform数据库中存储图片是二进制的,现在却不能在datagridview中显示出来,求高手支招。、我的PHP数据库中有些内容有图片,有些没有,如何判定图片显示、数据库里有数据。网站却显示不出来。这是怎么回事。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10192245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存