السلام عليكم
الكود التالي للبحث في قاعدة البيانات عن اسم القطعة وعرضها في DataGridView، ربما يفيدك:
الكود التالي للبحث في قاعدة البيانات عن اسم القطعة وعرضها في DataGridView، ربما يفيدك:
PHP كود :
Private Sub SearchByPartDescription()
Dim LSQL As String = "select * from Parts where Description like '%" & txtSearchByPartDescription.Text & "%' order by ID"
Dim LAdapter As New OleDbDataAdapter(LSQL, Con)
Dim LDataSet As New DataSet
Dim RowsCount As Integer
Dim i As Integer
dgvParts.Rows.Clear()
If Con.State = ConnectionState.Closed Then
Con.Open()
LAdapter.Fill(LDataSet, "Parts")
RowsCount = LDataSet.Tables("Parts").Rows.Count
If RowsCount = 0 Then
dgvParts.Rows.Clear()
LDataSet.Reset()
Con.Close()
Exit Sub
Else
dgvParts.Rows.Add(RowsCount)
' Now: fill DGV with data
For i = 0 To RowsCount - 1
With dgvParts
.Rows(i).Cells(0).Value = LDataSet.Tables("Parts").Rows(i).Item("ID")
.Rows(i).Cells(1).Value = LDataSet.Tables("Parts").Rows(i).Item("Description")
.Rows(i).Cells(2).Value = LDataSet.Tables("Parts").Rows(i).Item("Quantity")
.Rows(i).Cells(3).Value = LDataSet.Tables("Parts").Rows(i).Item("UnitCostPrice")
.Rows(i).Cells(4).Value = LDataSet.Tables("Parts").Rows(i).Item("UnitSellingPrice")
.Rows(i).Cells(5).Value = LDataSet.Tables("Parts").Rows(i).Item("CountryOfOrigine")
.Rows(i).Cells(6).Value = LDataSet.Tables("Parts").Rows(i).Item("BarcodeNumber")
End With
Next
LDataSet.Reset()
Con.Close()
End If
Else
LAdapter.Fill(LDataSet, "Parts")
RowsCount = LDataSet.Tables("Parts").Rows.Count
If RowsCount = 0 Then
dgvParts.Rows.Clear()
LDataSet.Reset()
Con.Close()
Exit Sub
Else
dgvParts.Rows.Add(RowsCount)
' Now: fill DGV with data
For i = 0 To RowsCount - 1
With dgvParts
.Rows(i).Cells(0).Value = LDataSet.Tables("Parts").Rows(i).Item("ID")
.Rows(i).Cells(1).Value = LDataSet.Tables("Parts").Rows(i).Item("Description")
.Rows(i).Cells(2).Value = LDataSet.Tables("Parts").Rows(i).Item("Quantity")
.Rows(i).Cells(3).Value = LDataSet.Tables("Parts").Rows(i).Item("UnitCostPrice")
.Rows(i).Cells(4).Value = LDataSet.Tables("Parts").Rows(i).Item("UnitSellingPrice")
.Rows(i).Cells(5).Value = LDataSet.Tables("Parts").Rows(i).Item("CountryOfOrigine")
.Rows(i).Cells(6).Value = LDataSet.Tables("Parts").Rows(i).Item("BarcodeNumber")
End With
Next
LDataSet.Reset()
Con.Close()
End If
End If
End Sub

