 |
|
Dim consql As String = "Data Source=TCJSRVDB02;Initial Catalog=BussinessApplication;User ID=sa"
Dim connection As New SqlConnection(consql)
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim constr As String = ""
Dim savefolder As String = "R:\MRD\image\"
Dim strFullPath As String = savefolder
Dim dlg As New OpenFileDialog()
If dlg.ShowDialog() = DialogResult.OK Then
'*** Create Folder
If Not Directory.Exists(strFullPath) Then
Directory.CreateDirectory(strFullPath)
End If
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
'*** Save File
Dim filePath As String = dlg.FileName
Dim fileName As String = Path.GetFileName(filePath)
File.Copy(filePath, savefolder & fileName, True)
Dim command = New SqlCommand(constr, connection)
constr = "INSERT INTO pathImage(txtNumber,txtName,txtGroup,txttime,Filename,Filepath,FileSize) " & _
" VALUES (@txtNumber,@txtName,@txtGroup,@txttime,@Filename,@filepath,@fileSize)"
With command
command.Connection = connection
command.CommandText = constr
command.CommandType = CommandType.Text
command.Parameters.AddWithValue("@txtNumber", txtnumber.Text)
command.Parameters.AddWithValue("@txtName", txtname.Text)
command.Parameters.AddWithValue("@txtGroup", combogroup.Text)
command.Parameters.AddWithValue("@txtTime", DateTime.Now)
command.Parameters.AddWithValue("@FileName", txtnameimage.Text)
command.Parameters.AddWithValue("@FilePath", savefolder & fileName)
command.Parameters.AddWithValue("@FileSize", (New FileInfo(filePath).Length) / 1024)
command.ExecuteNonQuery()
End With
MessageBox.Show("อัพโหลดรูปภาพเรียนร้อย")
connection.Close()
showdata()
จาก code ตอนนี้ save ได้ปกติ แต่ ชื่อใน sql และ ชื่อที่เก็บไว้ มันเป็นชื่อตามรูป เลยอยากให้ ตอน save ให้ตั้งชื่อใหม่ครับ
รบกวนด้วยครับ
Tag : ASP, Ms SQL Server 2012, VB.NET, VS 2010 (.NET 4.x), Windows
|
|
 |
 |
 |
 |
Date :
2020-02-14 09:20:41 |
By :
chatchawan5897 |
View :
962 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |