 |
|
ขอดูตัวอย่าง Code ของการ Insert พวกไฟล์ pdf และ พวก word excel ลงไปในฐานข้อมูลหน่อยครับ |
|
 |
|
|
 |
 |
|
ลืมบอกครับผมใช้ vb.net เขียน เป็น win app นะครับ
|
 |
 |
 |
 |
Date :
2012-08-08 16:28:09 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ชัวร์รึเปล่าครับ ว่า มัน Error ฟิลด์นั้น ดูฟิลด์อื่นๆด้วยเด้อ เพราะ Max มันก็ 8000 อยู่แล้วนินา
|
 |
 |
 |
 |
Date :
2012-08-08 16:45:39 |
By :
13crowns |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
'txtPathFile เป็น textbox เก็บ path ตอน brows
Dim filePath As String = txtPathFile.Text.Trim()
Dim name() As String = Split(filePath, "\")
Dim filename As String = Path.GetFileName(filePath)
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes() As Byte = br.ReadBytes(CInt(fs.Length))Code (VB.NET)
MessageBox.Show(bytes.Length.ToString)
br.Close()
fs.Close()
'insert the file into database
tr = Conn.BeginTransaction
Try
Dim strQuery As String = "INSERT INTO tblFileScan(JobNo, NameFile,FileBinary,CreateBy,CreateDate) values (@JobNo, @NameFile, @FileBinary, @CreateBy, @CreateDate)"
com = New SqlCommand
With com
.Connection = Conn
.CommandText = strQuery
.CommandType = CommandType.Text
.Transaction = tr
.Parameters.Add("@JobNo", SqlDbType.VarChar).Value = "1234"
.Parameters.Add("@NameFile", SqlDbType.VarChar).Value = name(name.Length - 1)
' Parameters.Add("@FileType", SqlDbType.VarChar).Value = "application/vnd.ms-excel"
.Parameters.Add("@FileBinary", SqlDbType.Image).Value = bytes
.Parameters.Add("@CreateBy", SqlDbType.VarChar).Value = DBConnString.UserName
.Parameters.Add("@CreateDate", SqlDbType.DateTime).Value = Now
.ExecuteNonQuery()
End With
tr.Commit()
Catch ex As Exception
MessageBox.Show(ex.ToString, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
tr.Rollback()
End Try
|
 |
 |
 |
 |
Date :
2012-08-08 17:17:41 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูให้หน่อยนะครับ ว่ามันผิดตรงไหน
|
 |
 |
 |
 |
Date :
2012-08-08 17:19:29 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2012-08-08 17:30:48 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บชื่อไฟล์จะดีกว่าน่ะครับ
|
 |
 |
 |
 |
Date :
2012-08-08 17:34:40 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันปัจจุบันก็เก็บ path ครับแต่พอดีหัวหน้าเขาอยากให้เก็บเป็นไฟล์ลง DB นะครับเพราะว่ามันใช้หลายเครื่องเขาอยากให้คนอื่นสามารถเรียกดูทุกไฟล์ที่ได้ทำการ Scan จากเครื่องต่างๆได้ ถ้ามีอะไรชี้แนะ แนะนำหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2012-08-08 17:41:39 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก Error ก็น่าจะตามนั้นครับ คือมันน่าจะใหญ่กว่าที่จะจัดเก็บได้ครับ 
|
 |
 |
 |
 |
Date :
2012-08-08 20:41:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-08-09 08:53:36 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://msdn.microsoft.com/en-us/library/ms188362.aspx
อ่านดู
Remarks
When n is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified with the CAST function, the default length is 30.
Use binary when the sizes of the column data entries are consistent.
Use varbinary when the sizes of the column data entries vary considerably.
Use varbinary(max) when the column data entries exceed 8,000 bytes.
---------------------------------
เอา google แปลให้
ข้อคิดเห็น
เมื่อ n ไม่ได้ระบุในความหมายของข้อมูลหรือคำสั่งประกาศตัวแปรความยาวเริ่มต้นคือ 1 เมื่อ n ไม่ได้ระบุด้วยฟังก์ชัน CAST, ความยาวเริ่มต้นคือ 30
ใช้เลขฐานสองเมื่อขนาดของรายการข้อมูลของคอลัมน์ที่สอดคล้อง
ใช้ varbinary เมื่อขนาดของรายการข้อมูลคอลัมน์แตกต่างกันมาก
ใช้ varbinary (สูงสุด) เมื่อรายการข้อมูลคอลัมน์เกิน 8,000 ไบต์
|
 |
 |
 |
 |
Date :
2012-08-09 09:29:04 |
By :
ชื่อนั้นไม่สำคัญหรอก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|