####อันนี้โค๊ด Browse ไฟล์ครับ#####
Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
With OpenFileDialog1
.Filter = "PDF Files (*.gif;*.JPG;*.pdf)|*.gif;*.JPG;.*.pdf|All Files(*.*)|*.*"
.FileName = ""
If (.ShowDialog() = DialogResult.OK) Then
TextBox6.Text = .FileName
'PictureBox1.Image = System.Drawing.Image.FromFile(.FileName)
End If
Process.Start(.FileName)
End With
End Sub
Code (VB.NET)
####อันนี้โค๊ด Save ไฟล์ครับ#####
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim constr As String = "Provider = microsoft.ace.oledb.12.0;Data Source = " & Application.StartupPath & "\DB2.accdb;"
If Not conn.State = ConnectionState.Open Then
conn.Open() 'เปิดการเชื่อมต่อกับฐานข้อมูล
End If
Dim sql As String
If txtConsumer.Text = "" Then
sql = "INSERT INTO Detail_Job(Item,Quotation,Check_sheet_for_customer,Thermal_stress_reliver,Weld_Inspection,Sand_Blasting,Primer_Coat,Top_Coat,Sheet,Timing,Due_date,File)"
sql += "VALUES(@Item,@Quotation,@Check_sheet_for_customer,@Thermal_stress_reliver,@Weld_Inspection,@Sand_Blasting,@Primer_Coat,@Top_Coat,@Sheet,@Timing,@Due_date,@File)"
Dim cmd As New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("Item", Me.TextBox27.Text)
cmd.Parameters.AddWithValue("Quotation", Me.txtDrawing.Text)
cmd.Parameters.AddWithValue("Check_sheet_for_customer", Me.CheckBox1.Text)
cmd.Parameters.AddWithValue("Thermal_stress_reliver", Me.CheckBox2.Text)
cmd.Parameters.AddWithValue("Weld_Inspection", Me.CheckBox3.Text)
cmd.Parameters.AddWithValue("Sand_Blasting", Me.CheckBox4.Text)
cmd.Parameters.AddWithValue("Primer_Coat", Me.TextBox18.Text)
cmd.Parameters.AddWithValue("Top_Coat", Me.TextBox3.Text)
cmd.Parameters.AddWithValue("Sheet", Me.NumericUpDown1.Text)
cmd.Parameters.AddWithValue("Timing", Me.NumericUpDown2.Text)
cmd.Parameters.AddWithValue("Due_date", Me.DateTimePicker4.Text)
Dim fr As New FileStream(TextBox6.Text, FileMode.Open, FileAccess.Read)
Dim binreader As New BinaryReader(fr)
Dim File() As Byte = binreader.ReadBytes(fr.Length)
cmd.Parameters.AddWithValue("File", SqlDbType.NVarChar).Value = File
Dim a As Integer = cmd.ExecuteNonQuery()
If (a = -1) Then
MessageBox.Show("เกิดข้อผิดพลาดในการบันทึกข้อมูล", "Warning")
Else : MessageBox.Show("ข้อมูลถูกจัดเก็บแล้ว", "Result")
End If
RefreshDatadetail()
conn.Close()
End Sub
Database File = OLE Object หรือ Hyperlink ดีครับ #เก็บข้อมูลเป็น pdf ครับ#
ขอบคุณมากๆ นะครับ
Tag : Ms Access, VBScript, Crystal Report, Win (Windows App), VB.NET
With OpenFileDialog1
.Filter = "PDF Files (*.PDF)|*.PDF|All Files(*.*)|*.*"
.FileName = ""
If (.ShowDialog() = DialogResult.OK) Then
TextBox6.Text = .FileName
End If
If TextBox6.Text = .FileName Then
'PictureBox1.Image = System.Drawing.Image.FromFile(.FileName)
Dim FileToCopy As String
Dim NewCopy As String
FileToCopy = TextBox6.Text
NewCopy = "C:\mrptest\mrptest\bin\Debug\File\" + (txtDrawing.Text) + (".PDF")
If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)
End If
End If
End With