Adding an image to SQL database using Visual C#

前端 未结 4 1504
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 20:16

I am working on a visual C# program for image processing.I am trying to add image to sql database using Visual C# (Windows forms) and ADO.NET.

I have converted the i

4条回答
  •  渐次进展
    2020-12-06 20:53

    Try with something like this:

    byte[] fileBytes=System.IO.File.ReadAllBytes("path to file");
    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("insert  into table(blob,filename) values (@blob,@name)");
    command.Parameters.AddWithValue("blob", fileBytes);
    command.Parameters.AddWithValue("name", "filename");
    command.ExecuteNonQuery();
    

提交回复
热议问题