我想使用Windows应用程序的C#从GridView中的数据库中分发图像 [英] I want to dispaly image from database in GridView using c# for windows application

查看:58
本文介绍了我想使用Windows应用程序的C#从GridView中的数据库中分发图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows窗体c#上工作,并且我想在gridview中显示数据库中的图像但我在很多尝试中都做不到.

I am working on windows form c# and I want display images from database in gridview But i can''t do this in so many tries.

private void GetData(string selectCommand)
        {
   try
   {
String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\ODYSSEY\Downloads\Documents\Panorama
\MyImages.mdf;
Integrated Security=True;User Instance=True";
 
SqlDataAdapter adap = new SqlDataAdapter(selectCommand, connectionString);

SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adap);
DataTable table = new DataTable();
 table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        adap.Fill(table);
               dataGridView1.DataSource = table;
                dataGridView1.AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
            }
            catch (SqlException)
            {
                MessageBox.Show("Error to load data from database, Please check it.....");
            }
        }

 private void viewall_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = dataGridView1;
GetData("select ImageData from ImageData");
}



它显示行,但不显示行中的图像...



it show rows but it do not display images in rows...

推荐答案

我曾经做过类似的事情,但是全部来自界面构建器使用数据绑定,当我这样做时,它会自动检测图像并显示它们.

有几个小问题:它是否以正确的图像名称显示该列,图像在数据库中具有哪种数据类型,当您完全从界面生成器中进行操作时它是否起作用?

如果它确实显示了该列并且具有正确的名称,则可能只需要为该图像显示行高即可.

如果您需要进一步的帮助,请发表回复.

PS.作为一个小提示,请看一下app.config文件.这些是存储诸如数据库连接字符串之类的设置的理想选择: http: //generally.wordpress.com/2007/09/27/using-appconfig-for-user-defined-runtime-parameters/ [
I once did something similar, but all from the interface builder using databinding, when I did it that way it automatically detected the images and displayed them.

A few small questions: does it show the column with the correct name for the images, what datatype do your images have in the database, does it work when you do it completely from the interface builder.

If it does show the column, and it has the correct name, maybe you simply need to a row height for the image to show.

Please post a reply if you need further help.

PS. As a small extra tip, take a look at app.config files. Those are ideal for storing settings like database connection strings: http://generally.wordpress.com/2007/09/27/using-appconfig-for-user-defined-runtime-parameters/[^]


这篇关于我想使用Windows应用程序的C#从GridView中的数据库中分发图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆