如何使用C#VS2008和MS acess 2003在窗口应用程序中从数据库中显示datagridview中的图像 [英] how to display images in datagridview from database in window application using C# VS2008 and MS acess 2003

查看:72
本文介绍了如何使用C#VS2008和MS acess 2003在窗口应用程序中从数据库中显示datagridview中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单中,我使用了一个组合框来显示Plantname

和按钮控制的点击事件我从数据库中检索相关信息。我使用datagridview进行数据显示。我还想在datagridview中显示工厂图像。它可以在Web应用程序中但如何在窗口应用程序中执行。





我能够在datagridview中显示值当我点击特定单元格时,文本的值被复制到textbox1.text ..





现在我想要的图像在textbox1上显示的同名名称。我使用了一个图片框,点击datagridview单元格或文本框,图片一个接一个地显示,使用下面的代码



private void Disease_Load(object sender,EventArgs e)

{



String constring =Data Source = | DataDirectory | abc。 mdb; Jet OLEDB:数据库密码= abc#;提供者= Microsoft.jet.oledb.4.0;

OleDbConnection conn = new OleDbConnection(constring);

OleDbDataAdapter da1 =新的OleDbDataAdapter(从疾病中选择独特的疾病,conn);

DataSet dset1 = new Da taSet();

da1.Fill(dset1,疾病);



if(dset1.Tables [Diseases]。 Rows.Count> 0)

{



comboBox1.DataSource = dset1.Tables [疾病];

comboBox1。 DisplayMember =DCur;

comboBox1.ValueMember =DCur;

comboBox1.SelectedIndex = 0;

// IHBT(CSIR)

}

conn.Close();

}



private void button2_Click(object sender,EventArgs e)

{

try

{

String Constring =Data Source = | DataDirectory | abc.mdb; Jet OLEDB:Database Password = abc#; Provider = Microsoft.jet.oledb.4.0;

OleDbDataAdapter da3 = new OleDbDataAdapter(SELECT Photograph.Photographs,Diseases.SName AS SName FROM(Systematics INNER JOIN Photograph on Systematics。[ID] =照片。[ID])INNER JOIN疾病开启系统。 [SName] =疾病。[SName]其中DCured ='+ comboBox1.Text +',Constring);

DataSet dset3 = new DataSet();

da3.Fill(dset3,RIT);



if(dset.Tables [RIT]。Rows.Count> 0)

{

dataGridView2.DataSource = dset.Tables [0];

dataGridView4.DataSource = dset3.Tables [0];



textBox1.Text = dset3.Tables [NIT]。行[ 0] [照片]。ToString();

pictureBox1.Load(Application.StartupPath +//+ textBox1.Text);



}

}

catch(例外情况)

{

MessageBox.Show(例如消息,NIT,MessageBoxButtons.RetryCancel,MessageBoxIcon.Warning);

}

}



< br $>








private void dataGridView4_CellContentClick(object sender,DataGridViewCellEventArgs e)< br $>


{

textBox1.Text = Convert.ToString(dataGridView4.CurrentRow.Cells [Photographs]。Value);

}



回复如果有人知道答案

In my form I have taken one combobox where I use to display the Plantname
and on click event of button control Im retrieving the related information from the database . I have used datagridview for data display . I also want to display the plant images in a datagridview . Its is possible in web application but how to do it in a window application.


I'm able to display values in the datagridview and when i click on the particular cell that value of the text get copied to textbox1.text ..


Now i want the image of that same name which got displayed at textbox1..I have used one picture box where on clicking the datagridview cell or textbox the images get displayed one after one im using the code below

private void Disease_Load(object sender, EventArgs e)
{

String constring = "Data Source=|DataDirectory|abc.mdb;Jet OLEDB:Database Password=abc#;Provider=Microsoft.jet.oledb.4.0";
OleDbConnection conn = new OleDbConnection(constring);
OleDbDataAdapter da1 = new OleDbDataAdapter("Select Distinct DCured from Diseases", conn);
DataSet dset1 = new DataSet();
da1.Fill(dset1, "Diseases");

if (dset1.Tables["Diseases"].Rows.Count > 0)
{

comboBox1.DataSource = dset1.Tables["Diseases"];
comboBox1.DisplayMember = "DCur";
comboBox1.ValueMember = "DCur";
comboBox1.SelectedIndex = 0;
//IHBT(CSIR)
}
conn.Close();
}

private void button2_Click(object sender, EventArgs e)
{
try
{
String Constring = "Data Source=|DataDirectory|abc.mdb; Jet OLEDB:Database Password= abc#; Provider=Microsoft.jet.oledb.4.0";
OleDbDataAdapter da3 = new OleDbDataAdapter("SELECT Photograph.Photographs,Diseases.SName AS SName FROM (Systematics INNER JOIN Photograph ON Systematics.[ID] = Photograph.[ID]) INNER JOIN Diseases ON Systematics.[SName] = Diseases.[SName] Where DCured='" + comboBox1.Text + "'", Constring);
DataSet dset3 = new DataSet();
da3.Fill(dset3, "RIT");

if (dset.Tables["RIT"].Rows.Count > 0)
{
dataGridView2.DataSource = dset.Tables[0];
dataGridView4.DataSource = dset3.Tables[0];

textBox1.Text = dset3.Tables["NIT"].Rows[0]["Photographs"].ToString();
pictureBox1.Load(Application.StartupPath + "//" + textBox1.Text);

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "NIT", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
}
}






private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)

{
textBox1.Text = Convert.ToString(dataGridView4.CurrentRow.Cells["Photographs"].Value);
}

reply if anybody know the answer

推荐答案

如何:在Windows窗体DataGridView控件的单元格中显示图像 [ ^ ]

如何使用C#和Windows窗体向DataGridView单元添加图像 [ ^ ]


这篇关于如何使用C#VS2008和MS acess 2003在窗口应用程序中从数据库中显示datagridview中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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