SoFunction
Updated on 2025-03-08

C# How to save pictures to the database and read and display pictures


private void button2_Click_1(object sender, e)

{

string pathName;

if (this.()==)

{

pathName = this.;

img = (pathName);

this. = img;

//Read the image into the byte array

fs = new (pathName,,);

byte[] buffByte = new byte[];

(buffByte,0,(int));

();

fs = null;

//Create Command

string comm = @"Insert into table1(img,name) values(@img,@name)";

this.sqlCommand1 = new ();

this. = ;

this. = comm;

this. = this.sqlConnection1 ;

//Create Parameter

this.("@img",);

this.[0].Value = https:///ianakin/archive/2012/02/02/buffByte;

this.("@name",);

this.[1].Value =https:///ianakin/archive/2012/02/02/(("\\")+1);

try

{

this.();

this.();

this.();

}

catch( ee)

{

( );

}

buffByte = null;

();

}