2016-03-30 6 views
0

バイナリロングデータとして保存されているアクセスデータベースからイメージを取得しようとしています。私は他のデータと一緒にdatagridviewに画像を表示したい。アクセスデータベースからイメージ(ロングバイナリデータ)を取得し、C#でグリッドビューに表示します。

image in Datagridview

String sql = "SELECT Config.ConfigID, Config.ProductName, Config.Features, Config.Price, Config.Picture, Stock.Quantity, Stock.TotalPrice FROM Config INNER JOIN Stock ON Config.ConfigID = Stock.ConfigID"; 
       cmd = new OleDbCommand(sql, con); 
       rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); 
       dataGridView1.Rows.Clear(); 
       try 
       { 
        while (rdr.Read() == true) 
       { 
        dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5], rdr[6]); 


       } 
       con.Close(); 
       } 

答えて

1

これを試してみてください:

while (rdr.Read() == true) 
{ 
    string path = @"c:\mytest.bmp"; 
    int pictureCol = 4; // the column # 
    Byte[] b = new Byte[(rdr.GetBytes(pictureCol, 0, null, 0, int.MaxValue))]; 
    rdr.GetBytes(pictureCol, 0, b, 0, b.Length); 
    using(System.IO.FileStream fs = new System.IO.FileStream(path, 
       System.IO.FileMode.Create,System.IO.FileAccess.Write)) 
    { 
     fs.Write(b, 0, b.Length); 
    } 

    dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5], rdr[6], 
               Bitmap.FromFile(path)); 
} 
+0

は弟を働いていない、私はそれと追加画像添付ファイルをご参照ください。 –

+0

何が問題なのですか? 'GetBytes'または' Bitmap.FromFile'? –

+0

いいえ、その言う、DestFilePathは既に別のプログラムで使用中です。 –

関連する問題