MFI Suite. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

MFI Suite.

ossyossy Posts: 2Member
The program has two tables, 'tblclients and tblgroup' a number of clients in tblclients belong to a particular group in tblgroup. I have difficulties trying to tie both tables in specific.
Here is my code:

Imports System.Data.OleDb

Public Class frmSearchClient
Dim CNString As String
Dim CN As New OleDbConnection
Dim cmd As New OleDbCommand
Dim dsNewRow As DataRow
Dim sql As String
Dim inc As Integer
Dim ds As New DataSet
Dim da As New OleDbDataAdapter


Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim dbProvider As String
Dim dbSource As String
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:LOCUS MICROFINANCE SUITESAddressBookTrial.mdb"
CN.ConnectionString = dbProvider & dbSource
Dim cmd As New OleDbCommand("SELECT * FROM Clients where ID like '%" + txtSearch.Text + "%'OR Surname like '%" + txtSearch.Text + "%' OR Firstname like '%" + txtSearch.Text + "%'", CN)
Dim cmd2 As New OleDbCommand("Select Group_Name FROM Groups", CN)
Dim Adpt As New OleDbDataAdapter(cmd)
Dim adpt1 As New OleDbDataAdapter(cmd2)
Dim ds As New DataSet()
If (Adpt.Fill(ds, "Clients")) And (adpt1.Fill(ds, "Groups")) Then
dgvSearch.DataSource = ds.Tables(0)
Else
MessageBox.Show("match not found")
End If
Dim sql1 As String
sql1 = "SELECT *, Group_Name FROM Clients, Groups"
Dim adapter1 As New OleDbDataAdapter(sql1, CN)
Dim cmd1 As New OleDbCommand(sql1, CN)
CN.Open()
Dim myreader As OleDbDataReader = cmd1.ExecuteReader
myreader.Read()

CN.Close()

End Sub

Private Sub dgvSearch_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvSearch.CellContentClick
frmNewClient.Show()
' Same thing as btnUpdate_Click except the user can actually DoubleClick
' a record. You want to be sure you get the field names and cell numbers
' correct or the information will be misconstrued.
frmNewClient.txtid.Text = dgvSearch.Rows(e.RowIndex).Cells(0).Value.ToString
frmNewClient.dtDate.Value = dgvSearch.Rows(e.RowIndex).Cells(1).Value.ToString
frmNewClient.cmbTitle.Text = dgvSearch.Rows(e.RowIndex).Cells(2).Value.ToString
frmNewClient.txtSurname.Text = dgvSearch.Rows(e.RowIndex).Cells(13).Value.ToString
frmNewClient.txtMiddleName.Text = dgvSearch.Rows(e.RowIndex).Cells(14).Value.ToString
frmNewClient.txtFirstname.Text = dgvSearch.Rows(e.RowIndex).Cells(15).Value.ToString
frmNewClient.cmbSex.Text = dgvSearch.Rows(e.RowIndex).Cells(3).Value.ToString
frmNewClient.dtDate_Of_Birth.Value = dgvSearch.Rows(e.RowIndex).Cells(4).Value.ToString
frmNewClient.txtHome_Address.Text = dgvSearch.Rows(e.RowIndex).Cells(5).Value.ToString
frmNewClient.txtCity.Text = dgvSearch.Rows(e.RowIndex).Cells(6).Value.ToString
frmNewClient.txtStateOfOrigin.Text = dgvSearch.Rows(e.RowIndex).Cells(7).Value.ToString
frmNewClient.cmbNationality.Text = dgvSearch.Rows(e.RowIndex).Cells(8).Value.ToString
frmNewClient.txtTelephone.Text = dgvSearch.Rows(e.RowIndex).Cells(9).Value.ToString
frmNewClient.cmbClientType.Text = dgvSearch.Rows(e.RowIndex).Cells(10).Value.ToString
frmNewClient.cmbBranch.Text = dgvSearch.Rows(e.RowIndex).Cells(11).Value.ToString
frmNewClient.btnUpdate.Visible = True
frmNewClient.SaveToolStripButton.Enabled = False

End Sub
End Class


Sign In or Register to comment.