C # Save Picture to Image field

xiaoxiao2021-03-06  52

Byte [] filebyteaRray; system.io.MemoryStream imagesTream;

this.sqlConnection1.ConnectionString = strConn; try {if (this.sqlConnection1.State == ConnectionState.Closed) this.sqlConnection1.Open (); this.sqlCommand1.CommandText = "insert into MyImage (MyImage) values ​​(@MyImage)" Imagestream = new memorystream (); image1.save (Imagestream, System.drawing.Imaging.ImageFormat.jpeg);

FileByteArray = new byte [control.Toint32 (Imagestream.length)];

Imagestream.read (FileByteaRray, 0, Convert.Toint32 (Imagestream.length);

. SqlCommand1.Parameters.Add (new SqlParameter ( "@ MyImage", SqlDbType.Image, Convert.ToInt32 (ImageStream.Length))) Value = FileByteArray; sqlCommand1.ExecuteNonQuery (); MessageBox.Show ( "Add success!"); } Catch (exception ex) {messagebox.show (ex.Message);

转载请注明原文地址:https://www.9cbs.com/read-117032.html

New Post(0)