 |
|
อยากถามเรื่องการเก็บ Path ลงใน Database Mysql อะครับ |
|
 |
|
|
 |
 |
|
คือผมทำการเขียนโค๊ด รับรูปภาพ จาก OpenFileDialog นะครับ
แล้วทำการ เก็บชื่อ Path ลงใน ตัวแปร open นะครับ
จากนั้นทำการ ส่ง Path ไปที่ Label อีกทีแล้วทำการ
insert into ......(.....) values ('" & Me.Label7.Text & "')"
แบบนี้อะคับ
แต่พอไปดูใน Database มัน เซฟ เป็น D:Folder1150.jpg แทนที่มันจะเป็น D\:Folder\1150.jpg
มันไม่ทำการ เซฟ ตัว "\" ให้อะครับ ต้องแก้ยังไงครับ
แต่ถ้าผมทำการ เพิ่ม ข้อมูลของ Path ลงใน Database โดยตรง สามารถเรียภาพจากโปรแกรม ได้ปกติ นะครับ ช่วยที
Code (VB.NET)
'อันนี้คือปุ่มเพิ่มรูปนะครับ'
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim open As New OpenFileDialog()
open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp"
If open.ShowDialog() = DialogResult.OK Then
Dim fileName As String = System.IO.Path.GetFullPath(open.FileName)
PictureBox1.Image = New Bitmap(open.FileName)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
End If
Me.Label7.Text = open.FileName.ToString
End Sub
'อันนี้เป็นปุ่มบันทึกครับ'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim connStr As String = "server=localhost;user id=root;password=1234; database =137"
Dim conn As MySqlConnection
conn = New MySqlConnection(connStr)
conn.Open()
Dim sql As String = "insert into employee(emp_code,emp_name,emp_address,emp_sex,emp_tel,emp_position,emp_picture) values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox7.Text & "','" & TextBox6.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & Me.Label7.Text & "')"
Dim cmd As MySqlCommand = New MySqlCommand(sql, conn)
cmd.ExecuteNonQuery()
conn.Clone()
conn.Dispose()
MsgBox("บันทึกแล้วครับ")
End Sub
ผมใช้ parameters ไม่เป็นเลยครับ
Tag : .NET, MySQL, VB.NET
|
|
 |
 |
 |
 |
Date :
2013-09-20 22:52:57 |
By :
MikeZaa |
View :
1318 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim fileName As String = "C:\mydir\myfile.ext"
Dim result As String = result = Path.GetFileName(fileName)
result เอาเฉพาะชื่อไฟล์ครับ
|
 |
 |
 |
 |
Date :
2013-09-21 07:59:51 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ชอคุณครับ
|
 |
 |
 |
 |
Date :
2013-09-21 10:47:52 |
By :
MikeZaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|