|
 |
|
รบกวนขอ Code C# อัพโหลดไฟล์ ดึงไฟล์ จาก MySQL Type:BLOB |
|
 |
|
|
 |
 |
|
C# window form นะคะ
mysql ไฟล์เก็บใช้ type: blob
ทำ form upload/retrieve ไฟล์ต่างๆ พวก word, excel, jpg ด้วย
เปิดหาไฟล์เราใช้ ประมาณนี้
Code (C#)
OpenFileDialog fDialog = new OpenFileDialog();
ตอนบันทึก ใช้แนวๆนี้ เข้า mysql ได้ค่ะ
Code (C#)
FileStream fs;
BinaryReader br;
long FileSize;
string FileName = textBox6.Text;
byte[] fileData;
fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
FileSize = fs.Length;
br = new BinaryReader(fs);
fileData= br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
string strQuery = "INSERT INTO f_file (f_id,f_name,f_size,f_byte) VALUES('" + fid + "', '" + fileName + "', '" + FileSize + "', '" + fileData + "') ";
DB.Insert(strQuery);
แต่ไม่รู้ว่าดึงไฟล์ออกมายังไง ให้คลิกที่จอแล้วค่อยเปิดไฟล์แบบนั้นค่ะ
Tag : .NET, MySQL, Win (Windows App), C#

|
ประวัติการแก้ไข 2013-10-09 10:19:07
|
 |
 |
 |
 |
Date :
2013-10-09 09:33:10 |
By :
noona |
View :
945 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
query ออกมาเป็น byte array
เอา byte array มาไรต์ออกเป็นไฟล์
ปล. จะกำหนด path กับชื่อไฟล์ที่จะ save ก็ใช้ savefiledialog
|
 |
 |
 |
 |
Date :
2013-10-09 09:41:32 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|