how can I load the images from the remote server in a data table C# windows form? I have stored only the image path in my Sqldatabase. when I am running the code it throws an exception of 404 error. same code is retriving the images on other forms
private void Datagrid() {
try
{
id.Text = "";
name.Text = "";
cost.Text = "";
price.Text = "";
description.Text = "";
status.Text = "";
picture.Image = null;
status.Items.Add("active");
status.Items.Add("inactive");
id.Visible = false;
label7.Text = "";
conn.Open();
MySqlCommand cm = new MySqlCommand();
// string query = "SELECT dealSuggestion_id,name,cost,price,description,Status from dealSuggestion where Status='inactive' LIMIT 8";
string query = "SELECT * from dealSuggestion where Status='inactive' LIMIT 8";
cm.CommandText = query;
cm.Connection = conn;
MySqlDataAdapter da = new MySqlDataAdapter(cm);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
string img = row["image"].ToString();
if (!row.IsNull("image"))
{
ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
System.Net.WebRequest request = System.Net.WebRequest.Create(row["image"].ToString());
System.Net.WebResponse resp = request.GetResponse();
System.IO.Stream respStream = resp.GetResponseStream();
Bitmap bmp = new Bitmap(respStream);
respStream.Dispose();
row["image"] = bmp;
}
}
dataGridView1.DataSource = dt;
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}