รบกวนช่วยเช็คโค๊ดให้หน่อยครับ อยากได้แบบเก็บรูปไว้ที่โฟลเดอร์อื่นๆเช่น D:\\pic ให้ไปเรียกใช้งานที่ part ที่กำหนดครับตอนนี้ผมทำได้แค่ไปเรียกจาก application path อย่างเดียวเท่านั้นครับ
Code (VB.NET)
Option Explicit On
Option Strict Off
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports vb = Microsoft.VisualBasic
Public Class TelSearch
Dim strConn As String
Dim conn As New OleDbConnection("provider=Microsoft.ace.oledb.12.0;data source=\\10.66.15.200\NYKAPP\Database2.accdb")
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim strSQL As String
Dim Check As Boolean
Dim Action As String
Dim IsFindProduct As Boolean
Dim IsFindDept As Boolean
Dim filename1 As String
Private Sub Showcustomersformcustomers()
Dim sql As String
If ds.Tables.Contains("Table2") Then ds.Tables("Table2").Clear()
FormatGrd()
sql = "Select add_firstname,add_lastname,add_nickname,add_department,add_position,add_extention,add_location,add_email.add_pic From Table2"
Dim da As New OleDbDataAdapter(sql, conn)
da.Fill(ds, "Table2")
grdProduct.DataSource = ds
grdProduct.DataMember = "Table2"
End Sub
Private Sub ShowData()
strSQL = "SELECT add_firstname,add_lastname,add_nickname,add_department,add_position,add_extention,add_location,add_email,add_pic FROM Table2"
da = New OleDbDataAdapter(strSQL, conn)
If IsFindProduct = True Then
ds.Tables("Table2").Clear()
End If
da.Fill(ds, "Table2")
If ds.Tables("Table2").Rows.Count <> 0 Then
grdProduct.DataSource = ds.Tables("Table2")
FormatGrd()
IsFindProduct = True
End If
End Sub
Private Sub ClearAllData()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
FormatGrd()
PictureBox1.Image = Nothing
TextBox2.Focus()
End Sub
Private Sub FormatGrd()
With grdProduct
If .RowCount <> 0 Then
.Columns(0).HeaderText = "Firstname"
.Columns(1).HeaderText = "Lastname"
.Columns(2).HeaderText = "Nickname"
.Columns(3).HeaderText = "department"
.Columns(4).HeaderText = "Position"
.Columns(5).HeaderText = "Extention"
.Columns(6).HeaderText = "Loctaion"
.Columns(7).HeaderText = "Email"
.Columns(8).HeaderText = "Picture"
.Columns(0).Width = 60
.Columns(1).Width = 80
.Columns(2).Width = 60
.Columns(3).Width = 70
.Columns(4).Width = 80
.Columns(5).Width = 80
.Columns(6).Width = 80
.Columns(7).Width = 80
.Columns(8).Width = 80
End If
End With
End Sub
Private Sub grdProduct_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grdProduct.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With grdProduct
TextBox2.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
TextBox3.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
TextBox4.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
TextBox5.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString()
TextBox6.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString()
TextBox7.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString()
TextBox8.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString()
TextBox9.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString()
TextBox1.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString()
filename1 = TextBox1.Text
PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
FormatGrd()
End With
End Sub
Private Sub TelSearch_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ShowData()
FormatGrd()
strConn = "provider=Microsoft.ace.oledb.12.0;data source=\\10.66.15.200\NYKAPP\Database2.accdb"
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sql As String
FormatGrd()
If ds.Tables.Contains("Table2") Then ds.Tables("Table2").Clear()
sql = "Select add_firstname, add_lastname, add_nickname, add_department, add_position, add_extention, add_location, add_email, add_pic from Table2 "
If RadioButton1.Checked = True Then
sql = sql + "where add_firstname Like '%" + TextBox10.Text + "%'"
ElseIf RadioButton2.Checked = True Then
sql = sql + "where add_lastname like '%" + TextBox10.Text + "%'"
ElseIf RadioButton3.Checked = True Then
sql = sql + "where add_nickname like '%" + TextBox10.Text + "%'"
ElseIf RadioButton4.Checked = True Then
sql = sql + "where add_department like '%" + TextBox10.Text + "%'"
ElseIf RadioButton5.Checked = True Then
sql = sql + "where add_position like '%" + TextBox10.Text + "%'"
ElseIf RadioButton6.Checked = True Then
sql = sql + "where add_extention like '%" + TextBox10.Text + "%'"
ElseIf RadioButton7.Checked = True Then
sql = sql + "where add_location like '%" + TextBox10.Text + "%'"
ElseIf RadioButton8.Checked = True Then
sql = sql + "where add_email like '%" + TextBox10.Text + "%'"
Else
filename1 = TextBox1.Text
PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
Dim da As New OleDbDataAdapter(sql, conn)
da.Fill(ds, "table2")
grdProduct.DataSource = ds
grdProduct.DataMember = "table2"
If ds.Tables("table2").Rows.Count <= 0 Then
MessageBox.Show("ไม่พบรายการที่ค้นหา !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ShowData()
End If
End Sub
End Class