2016-11-11 68 views
0

我有一个表中的文本,id和图像(blob)的MySQL,现在我需要显示在datagridview中的数据。这是我做过什么将Mysqldata绑定到datagridview会导致错误

MySqlConnection mysqlCon = new 

MySqlConnection(MySQLConnectionString); 
mysqlCon.Open(); 

MySqlDataAdapter MyDA = new MySqlDataAdapter(); 
string sqlSelectAll = "SELECT * from info"; 
MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon); 

DataTable table = new DataTable(); 
MyDA.Fill(table); 

dataGridView1.DataSource = new BindingSource(table,null); // Error at this line 

我收到以下错误

enter image description here

如何解决这个

编辑

我发现这个错误是因为一些图像是空的blob,当我选择所有行与图像,我不再得到错误。

反正是有约束力的

+0

它不需要绑定 - DGV无法将BLOB转换为图像列的图像。可能是数据问题。你是否手动尝试做某事? – Plutonix

+0

你好,请检查编辑 – Smith

+0

你有关于图像列做代码的代码吗? DGV的正常行为是仅显示DBNull的破碎图像 – Plutonix

回答

2

为Null值一DGV图片列中的正常行为是简单地展示经典破碎的形象期间将死的:

enter image description here

所以一定要没有代码在某处做某事导致错误。鉴于invalid parameter aksi请确保没有损坏/坏数据的行。您还可以指定一个默认的图像时所使用的数据是空:

// class var for the image 
private Image noImg = Properties.Resources.exclamation; 
... 
// set DS and specify null image for col: 
dgv2.DataSource = new BindingSource(dtSample, null); 
dgv2.Columns[2].DefaultCellStyle.NullValue = noImg; 

enter image description here

这可能不会做任何事情来解决你的问题,如果数据是实际损坏,或者如果你有一些代码是做导致错误的东西(如自定义格式化程序)。