《Mysql實(shí)例asp.net 將圖片上傳到mysql數(shù)據(jù)庫的方法》要點(diǎn):
本文介紹了Mysql實(shí)例asp.net 將圖片上傳到mysql數(shù)據(jù)庫的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
這是頁面上的按鈕單擊變亂
代碼如下:
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);
}
這是執(zhí)行插入的辦法
代碼如下:
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;
}
《Mysql實(shí)例asp.net 將圖片上傳到mysql數(shù)據(jù)庫的方法》是否對您有啟發(fā),歡迎查看更多與《Mysql實(shí)例asp.net 將圖片上傳到mysql數(shù)據(jù)庫的方法》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/13126.html