|
 |
|
C# จะแก้ไข (Upload file BLOB and Binary Data) ไม่ได้ครับ ช่วยดูให้ที |
|
 |
|
|
 |
 |
|
https://www.thaicreate.com/free-web-script/asp.net-upload-file-blob-binary-data.html
ของผมจะ ทำการ update แต่ไม่เข้าใจ ตรง //*** MimeType ***'// ไม่รุ้ว่าจะต้องแก้ยังไง ช่วยแถลงไขที

Code (C#)
protected void btnUpload_Click(object sender, EventArgs e)
{
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection objConn = new SqlConnection(strconn);
this.pnlForm.Visible = false;
if (string.IsNullOrEmpty(this.txtName.Text))
{
this.lblStatus.Text = "Please input Name.";
}
else
{
//*** Update Name ***'
strSQL = "UPDATE product SET ProductName=@ProductName , ProductDetail=@ProductDetail , ProductPrice=@ProductPrice WHERE ProductId = @ProductId ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = this.txtName.Text;
objCmd.Parameters.Add("@ProductDetail", SqlDbType.VarChar).Value = this.txtProductdetail.Text;
objCmd.Parameters.Add("@ProductPrice", SqlDbType.VarChar).Value = this.txtproductPrice.Text;
objCmd.Parameters.Add("@ProductId", SqlDbType.Int).Value = Request.QueryString["ProductId"];
objCmd.ExecuteNonQuery();
//*** Update Picture ***'
if (this.fUpload.HasFile == true)
{
//*** Read Binary Data ***'
byte[] imbByte = new byte[fUpload.PostedFile.InputStream.Length + 1];
fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length);
//*** MimeType ***'
string ExtType = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower();
string strMIME = null;
switch (ExtType)
{
case ".gif":
strMIME = "image/gif";
break;
case ".jpg":
case ".jpeg":
case ".jpe":
strMIME = "image/jpeg";
break;
case ".png":
strMIME = "image/png";
break;
default:
this.lblStatus.Text = "Invalid file type.";
return;
}
strSQL = "UPDATE files SET FilesName = @sFilesName , FilesType = @sFilesType WHERE FilesID = @sFilesID ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.Parameters.Add("@sFilesName", SqlDbType.Binary).Value = imbByte;
objCmd.Parameters.Add("@sFilesType", SqlDbType.VarChar).Value = strMIME;
objCmd.Parameters.Add("@ProductId", SqlDbType.Int).Value = Request.QueryString["ProductId"];
objCmd.ExecuteNonQuery();
}
this.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view.";
}
}
Tag : ASP.NET Web (ASP.NET), C#

|
ประวัติการแก้ไข 2012-09-05 10:35:31 2012-09-05 11:15:38
|
 |
 |
 |
 |
Date :
2012-09-05 10:34:16 |
By :
thewinner55 |
View :
1192 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ลงคือนี่ update ไม่ลงหรือว่ายังไงครับ ในตัวอย่างที่คุณดูมันก็ปกติครับ
|
 |
 |
 |
 |
Date :
2012-09-05 17:41:10 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|