Save Image Test in Access

xiaoxiao2021-03-06  50

Private void Button1_Click (Object Sender, System.Eventargs E)

{

OLEDBCONNECTION mycn = new oledbconnection ("provider = microsoft.jet.Oledb.4.0; data source = f: //dazhu.mdb");

Mycn.open ();

OLEDBCommand mycmd = new oledbcommand ("Update Info Set Picture = @ a", MyCnn);

FileStream MyStream = New FileStream ("f: //1.jpg", filemode.open, fileaccess.read;

Long len = mystream.length;

Mycmd.Parameters.Add ("@ a", oledbtype.binary, (int) Len, "Picture");

Mycmd.parameters ["@ a"]. Direction = system.data.parameterDirection.input;

Byte [] box = new byte [len];

MyStream.read (Box, 0, (INT) LEN);

Mycmd.parameters ["@ a"]. value = box;

// Update

Mycmd.executenonquery ();

Messagebox.show ("OK");

MyStream.close ();

Mycnn.close ();

}

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

New Post(0)