Aasif Rao

Aasif Rao

  • NA
  • 5
  • 725

image viewing in data grid view in dbms

Jan 11 2018 5:17 AM
i have saved record with image of student in library management system and student_image has variable varchar(50).
but when i  tried to display in grid view also then it shows exception of "perimeter is not valid"
please suggest me solution .
error occurs in line where i used ### in code below. 
 
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{


dataGridView1.Columns.Clear();
dataGridView1.Refresh();
int i = 0;
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from student_info where student_name like('%"+ textBox1.Text +"%') ";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;

Bitmap img;
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
imageCol.HeaderText = "student_image";
imageCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
imageCol.Width = 100;
dataGridView1.Columns.Add(imageCol);
foreach (DataRow dr in dt.Rows)
{
#### img = new Bitmap(@"..\..\" + dr["student_images"].ToString());
dataGridView1.Rows[i].Cells[8].Value = img;
dataGridView1.Rows[i].Height = 100;
i = i + 1;
}
}
}

}
 

Answers (1)