I'm trying to display images from url that their path is in sqlite database on DataGridView cell.
But I just a string "System.Drawing.Bitmap" on the cell that want to display images.
Here is the source code.
Please help me.
Thank you in advance
string strConn = @"Data Source=C:\carku\carku.db";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SQLiteConnection conn = new SQLiteConnection(strConn))
{
conn.Open();
SQLiteCommand comm = new SQLiteCommand("select carName,mission,color,thumnail_url From cars", conn);
using (SQLiteDataAdapter sda =new SQLiteDataAdapter(comm))
{
DataSet ds = new DataSet();
sda.Fill(ds, "Emp");
dataGridView1.Columns.Add("carName", "carName");
dataGridView1.Columns.Add("mission", "mission");
dataGridView1.Columns.Add("color", "color");
dataGridView1.Columns.Add("thumnail_url", "thumnail_url");
int row = ds.Tables["Emp"].Rows.Count - 1;
for (int r = 0; r <= row; r++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2];
System.Net.WebClient webSource = new System.Net.WebClient();
string url = ds.Tables["Emp"].Rows[r].ItemArray[3].ToString() ;
byte[] data = webSource.DownloadData(url);
System.IO.MemoryStream pipe = new System.IO.MemoryStream(data);
Image jpgImage = Image.FromStream(pipe);
dataGridView1.Rows[r].Cells[3].Value = jpgImage;
}
}
conn.Close();
}
}
What I have tried:
System.Net.WebClient webSource = new System.Net.WebClient();
string url = ds.Tables["Emp"].Rows[r].ItemArray[3].ToString() ;
byte[] data = webSource.DownloadData(url);
System.IO.MemoryStream pipe = new System.IO.MemoryStream(data);
Image jpgImage = Image.FromStream(pipe);
DataGridViewImageColumn img_col= new DataGridViewImageColumn();
dataGridView1.Rows[r].Cells["img_col"].Value = jpgImage;
it doesn't work