Private Sub txtSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyDown
If txtSearch.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
Dim sqlProduct As String = ""
sqlProduct = "SELECT Product.ProductID,Product.ProductName,Product.Detail,Product.ProductPrice,"
sqlProduct &= " Use.MaterialID,Use.ManufactoryNum,"
sqlProduct &= " Material.MaterialName,Material.Unit"
sqlProduct &= " FROM Product,Use,Material"
If cboSearch.SelectedIndex = 0 Then
sqlProduct &= " WHERE (Product.ProductID='" & txtSearch.Text & "')"
ElseIf cboSearch.SelectedIndex = 1 Then
sqlProduct &= " WHERE (Product.ProductName='" & txtSearch.Text & "')"
End If
sqlProduct &= " AND (Use.ProductID=Product.ProductID)"
sqlProduct &= " AND (Material.MaterialID=Use.MaterialID)"
sqlProduct &= " ORDER BY Use.MaterialID"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
If IsFind = True Then
ds.Tables("Product").Clear()
End If
da = New OleDbDataAdapter(sqlProduct, Conn)
da.Fill(ds, "Product")
Dim N As Integer = 0
If ds.Tables("Product").Rows.Count <> 0 Then
IsFind = True
txtProductID.Text = CStr(ds.Tables("Product").Rows(0).Item("ProductID"))
txtProductName.Text = CStr(ds.Tables("Product").Rows(0).Item("ProductName"))
txtDetail.Text = CStr(ds.Tables("Product").Rows(0).Item("Detail"))
txtProductPrice.Text = CStr(ds.Tables("Product").Rows(0).Item("ProductPrice"))
While N < ds.Tables("Product").Rows.Count
Dim tmpID As String = ""
Dim tmpName As String = ""
Dim tmpNum As String = ""
Dim tmpUnit As String = ""
tmpID = CStr(ds.Tables("Product").Rows(N).Item("MaterialID"))
tmpName = CStr(ds.Tables("Product").Rows(N).Item("MaterialName"))
tmpNum = CStr(ds.Tables("Product").Rows(N).Item("ManufactoryNum"))
tmpUnit = CStr(ds.Tables("Product").Rows(N).Item("Unit"))
Dim lvi As ListViewItem
Dim anyData() As String
anyData = New String() { _
tmpID, _
tmpName, _
tmpNum, _
tmpUnit}
lvi = New ListViewItem(anyData)
lsvMaterialList.Items.Add(lvi)
N = N + 1
End While
dt = ds.Tables("Product")
btnAdd.Enabled = False
btnEdit.Enabled = True
btnEdit.Focus()
Else
IsFind = False
MessageBox.Show("ข้อมูลสินค้าที่คุณระบุ ไม่มี !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearData()
btnAdd.Enabled = True
btnEdit.Enabled = False
txtSearch.Focus()
txtSearch.SelectAll()
Exit Sub
End If
End If
End If
End Sub
Tag : .NET, Ms Access, Win (Windows App), VB.NET, C#