Image in datatable

后端 未结 2 551
不思量自难忘°
不思量自难忘° 2021-01-23 05:12

I read image by using OpenFileDialog. Sample code is below:

openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != null)
   if (picBoardImage.Image != nul         


        
2条回答
  •  无人共我
    2021-01-23 05:34

    You can do it like this -

    DataTable table = new DataTable("ImageTable"); //Create a new DataTable instance.
    
    DataColumn column = new DataColumn("MyImage"); //Create the column.
    column.DataType = System.Type.GetType("System.Byte[]"); //Type byte[] to store image bytes.
    column.AllowDBNull = true;
    column.Caption = "My Image";
    
    table.Columns.Add(column); //Add the column to the table.
    

    Then, add a new row to this table and set the value of the MyImage column.

    DataRow row = table.NewRow();
    row["MyImage"] = ;
    tables.Rows.Add(row);
    

    EDIT: You can take a look at this CodeProject article for help on converting an image to a byte array.

提交回复
热议问题