This is the button click event on the page
Copy Code code as follows:
protected void Button1_Click (object sender, EventArgs e)
{
String tid = Utils.getrandom (32);
Stream MyStream = this. FileUpload1.PostedFile.InputStream;
int length = this. FileUpload1.PostedFile.ContentLength;
byte[] pic = new Byte[length];
MyStream. Read (pic, 0, length);
BOOL FLG = insert (tid, pic);
}
This is the way to do the insertion
Copy Code code as follows:
public bool Insert (string tid,byte[] pic)
{
Dbconn db = new Dbconn ();
StringBuilder sql = new StringBuilder ();
Sql. Append ("INSERT into teacher (Tid,tphoto,tdelete) values (? tid,?pic,?flg)");
int FLG = 0;
Try
{
MyConnection = Db.getconnection ();
Mysqlcommand mycommand = new Mysqlcommand (SQL. ToString (), myconnection);
MYCOMMAND.PARAMETERS.ADD (New Mysqlparameter ("? Tid", Mysqldbtype.string, 32));
Mycommand.parameters["Tid"]. Value = tid;
MYCOMMAND.PARAMETERS.ADD (New Mysqlparameter ("? pic", Mysqldbtype.blob));
mycommand.parameters["? pic"]. Value = pic;
MYCOMMAND.PARAMETERS.ADD (New Mysqlparameter ("? Flg", mysqldbtype.int16));
mycommand.parameters["FLG"]. Value = 0;
Myconnection.open ();
FLG = Mycommand.executenonquery ();
}
catch (Exception ex)
{
return false;
}
Finally
{
if (myconnection!= null)
{
Myconnection.close ();
}
}
if (Flg > 0)
{
return true;
}
return false;
}