Skip to content
Loading
  • 0
    i hav store image path in sqldatabase but it can't show imge in column of gridview.
    please give me the c# coding about display image in gridview cell from sqldatabase .
    0
  • Laxmidhar Sahoo
    0
    hello in which format you store the image like image converted byte or in varchar that is the path of the file
    0
  • 0
    varchar(MAX) in which i store the image path
    0
  • 0
    private void Form2_Load(object sender, EventArgs e)
    {
    con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Admin\source\repos\DATABASE\data2.sql.mdf;Integrated Security=True;Connect Timeout=30");
    con.Open();
    adpt = new SqlDataAdapter("Select * from Details ", con);
    dt = new DataTable();
    adpt.Fill(dt);
    dataGridView.DataSource = dt;
    DataGridViewImageCell imgcol = new DataGridViewImageCell();
    dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
    dataGridView.RowTemplate.Height = 100;
    dataGridView.AllowUserToAddRows = false;
    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
    imageColumn = (DataGridViewImageColumn)dataGridView.Columns[13];
    imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
    con.Close();
    }
     
    BUT, IT SHOWS THE ERROR LIKE THIS: 
     
    System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Windows.Forms.DataGridViewImageColumn'.'
    0