问题描述
我正在使用 Visual Studio Express 2010 用 C# 开发桌面应用程序.
我在 MySQL 中有一个名为 Products 的表,其中包含 3 个字段:
ID -> Product_Name -> product_image
字段 product_Image
存储我硬盘中的图像路径(不是图像本身)
一个记录的例子是:
0001 --- 鼠标垫 XYZ ---- c:imagesmousepad.jpg
我想知道如何为我的 SQL 查询中的每条记录填充一个 datagridview
来显示 ID、产品名称,尤其是产品图片
.
我发现的所有示例都使用了手动数据插入,但我正在寻找一个示例来使用来自 SQL 查询的数据填充 datagridview,而不是手动插入.
感谢您的帮助,但无法直接应用解决方案.
我的表单上已经有一个 datagridview,我不需要在运行时创建.
我需要这样的东西(我会写一个通用的方式)
returnMySQL = "select * from products";而(返回MySQL){用 ID、产品名称、产品图片填充数据网格}
使用以下代码:
位图img;img = new Bitmap(@"c:imagesmousepad.jpg");//创建带有 Image 列的 DGVDataGridView dgv = 新 DataGridView();this.Controls.Add(dgv);DataGridViewImageColumn imageCol = new DataGridViewImageColumn();dgv.Columns.Add(imageCol);//添加一行并将其值设置为图像dgv.Rows.Add();dgv.Rows[0].Cells[0].Value = img;
参考链接.>
I am developing an application in C # for desktop using Visual Studio Express 2010.
I have a table in MySQL called Products with 3 fields:
The field product_Image
stores the image path in my hard drive (not the image itself)
An example of a record would be:
I wonder how fill a datagridview
that shows the ID, Produt name, and - especially - the product image
for each record in my SQL query.
All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.
Edit:
Thank you for help, but could not directly apply the solutions.
I already have a datagridview on my form, I have no need to create in runtime.
I need something like that (I'll write a generic way)
returnMySQL = "select * from products";
while (returnMySQL)
{
fill datagrid with ID, product name, product image
}
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
这篇关于如何在datagridview中显示图像?C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!