Compare data table with same column in different table vb.net - vb.net

I want to create evaluation program to compare two tables (entry and validation) whether they have same data or not. The number of column two tables are same. For Example there are T_A_Entry, T_A_Val, T_B_Entry, T_B_Val, T_C_Entry, T_C_Val, etc.
I have populated all tables in database with combobox. combobox1 to select entry table, combobox2 to select validation table, combobox3 to select column (but this is optional). I can't figure out how to make comparison in each column.
See image of the tables
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
svr = TextBox1.Text
ComboBox1.Items.Clear()
If Button1.Text = " Connected " Then
Button1.Text = "Connect"
cn.Close()
Exit Sub
End If
Call conDB()
Try
cn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
If cn.State = ConnectionState.Open Then
Button1.Text = "Connected"
comm.CommandText = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' ORDER BY 'TABLE_NAME' ASC"
dr = comm.ExecuteReader
If dr.HasRows Then
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
While dr.Read()
ComboBox1.Items.Add(dr("TABLE_NAME"))
ComboBox2.Items.Add(dr("TABLE_NAME"))
End While
End If
dr.Close()
cn.Close()
Else
MessageBox.Show("Fail to Connect")
Button1.Text = "Connect"
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim xsql As String
' mencari nama kolom tabel
xsql = " SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME= '" & ComboBox1.Text & "'"
Call conDB()
cn.Open()
comm.CommandText = xsql
dr = comm.ExecuteReader
If dr.HasRows Then
ComboBox3.Items.Clear()
While dr.Read()
ComboBox3.Items.Add(dr.Item(0))
End While
End If
dr.Close()
cn.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Call FillGrid(ComboBox1.Text, ComboBox2.Text, ComboBox3.Text)
End Sub
Private Sub FillGrid(ByVal tabelEntry As String, ByVal tabelValidasi As String, ByVal variabel As String)
Dim ds As New DataSet()
'helpp....
End Sub

Related

How can I solve System.Data.OleDb.OleDbException: 'Syntax error in FROM clause

Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Dimph\OneDrive\Desktop\Richfield BSC IT --- 1st year\Second Semester\Programming 512\Assignment\WinFormsApp1\WinFormsApp1\bin\Debug\net6.0-windows\Database2.accdb")
'
Private Sub btnLogin(sender As Object, e As EventArgs) Handles Button1.Click
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Enter Credentials", MsgBoxStyle.Exclamation)
Else
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim cmd As New OleDbCommand("select count(*) from User where UserName=? and Password=?", connection)
cmd.Parameters.AddWithValue("#1", OleDbType.VarChar).Value = txtUsername.Text
cmd.Parameters.AddWithValue("#2", OleDbType.VarChar).Value = txtPassword.Text
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
If (count > 0) Then
SplashSCreen.Show()
Else
MsgBox("Account not found on Database")
End If
End If
End Sub
Private Sub btnReset(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub btnSignUp(sender As Object, e As EventArgs) Handles Button3.Click
Form2.Show()
Me.Hide()
End Sub
Private Sub btnClose(sender As Object, e As EventArgs) Handles Button4.Click
Me.Close()
End Sub
End Class
User and Password are both reserved words and using them as object names can confuse the db engine. If you can't rename them, you can bracket them in your SQL so the db engine understands you're referring to objects.
select count(*) from [User] where UserName=? and [Password]=?
Or you could do it this way with fewer brackets:
select count(*) from [User] AS u where u.UserName=? and u.Password=?

How to Load DataGridView Fast

How can I load my data view faster?? I only have less than 300 data but it loads at least 10 secs.
here is my code
Public Class frmPopupStockout
Private Sub tsSelect_Click(sender As Object, e As EventArgs) Handles tsSelect.Click
Try
With frmStockOut
.txtPROCODE.Text = dtgList.CurrentRow.Cells(1).Value
Me.Close()
.txtJOS.Focus()
End With
Catch ex As Exception
End Try
End Sub
Private Sub FrmPopupStockout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
query = "SELECT PROCODE as [Part Number - Location - Process], PName AS [Part Name],PNumber AS [Part Number], STOCKLOC AS [Location],PROQTY AS [Quantity], PROCS AS [Process] FROM tblProductInfo"
retrieve(query, dtgList)
End Sub
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
query = "SELECT PROCODE as [Part Number - Location - Process], PName AS [Part Name],PNumber AS [Part Number], STOCKLOC AS [Location],PROQTY AS [Quantity], PROCS AS [Process] FROM tblProductInfo WHERE PROCODE LIKE '%" & txtSearch.Text & "%'"
retrieve(query, dtgList)
End Sub
Private Sub tsClose_Click(sender As Object, e As EventArgs) Handles tsClose.Click
Me.Close()
End Sub
End Class
Here is the code on retrieve query
Public Sub retrieve(ByVal query As String, ByVal dtg As DataGridView)
Try
con.Open()
cmd = New OleDb.OleDbCommand
With cmd
.Connection = con
.CommandText = query
End With
da = New OleDb.OleDbDataAdapter
da.SelectCommand = cmd
dt = New DataTable
da.Fill(dt)
dtg.Columns.Clear()
dtg.Columns.Add("count", "#")
dtg.DataSource = dt
Dim MAXROW As Integer = dt.Rows.Count - 1
For i = 0 To MAXROW
dtg.Rows(i).Cells(0).Value = i
Next
With dtg
.Columns(0).Width = 18
' .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
'.Columns(1).Visible = False
.Font = New Font("arial", 8, FontStyle.Bold)
.SelectionMode = False
End With
Catch ex As Exception
logs(ex.Message & " at retrieve sub Procedure")
MsgBox(ex.Message)
Finally
con.Close()
da.Dispose()
End Try
End Sub
When ever I try to load the Form with data grid it freezes for a while then it will load the form together with data.
I am retrieving the data from MS Access database, which have the front end together with the application and the backend at the Network Shared Files.
Problem Solved
I set these 2 from AllCells to DisplayedCells or None (AutosizeColumnsMode and AutoSizeRowsMode. and viola it loads faster
enter image description here

show patients that had a certain type of diagnose

I have a patient database. In that database i have a table "diagnosetypes" and a table with dossiers with a patient that received a certain diagnose.
In my diagnose form i have a list of diagnoses and now i want to add a listbox with a filter on all patients/dossiers that had this certain diagnose when that diagnose is selected in the combobox.
this is my current code
Public Class Diagnoses
Private Sub Diagnoses_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Tbl_DossiersTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Dossiers)
Me.Tbl_DiagnosesTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Diagnoses)
Dim dt = Tbl_DiagnosesBindingSource
cboxDiagnose.DataSource = dt
cboxDiagnose.DisplayMember = "Diag_Type"
txtDiagnoseBeschrijving.Text = dt(0)("Diag_Type").ToString
cboxDiagnose.Focus()
End Sub
Private Sub CboxDiagnose_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboxDiagnose.SelectionChangeCommitted
txtDiagnoseBeschrijving.Text = DirectCast(cboxDiagnose.SelectedItem, DataRowView)("Diag_Beschrijving").ToString
End Sub
Private Sub CboxDiagnose_Click(sender As Object, e As EventArgs) Handles cboxDiagnose.Click
RefreshData()
End Sub
Private Sub BtnAddDiagnose_Click(sender As Object, e As EventArgs) Handles btnAddDiagnose.Click
FormMakeDiagnoseType.Show()
End Sub
Private Sub RefreshData()
Try
Me.Tbl_DiagnosesBindingSource.Filter = Nothing
Me.Tbl_DiagnosesTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Diagnoses)
Catch ex As Exception
MsgBox("Refresh Data Error: " & ex.Message.ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Add New Record Failed!")
End Try
End Sub
End Class
edit: I changed my code to look like this as a way of trying to accomplish it myself , but i won't work.
Private Sub Diagnoses_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb")
cn.Open()
Dim cmmd As New OleDb.OleDbCommand("SELECT * FROM tbl_Dossiers WHERE OZ_ID.value = cboxDiagnose.text", cn)
Dim dr As OleDb.OleDbDataReader
dr = cmmd.ExecuteReader
Do While dr.Read
lboxPat_Diagcombo.Items.Add(dr("Rel_naam"))
Loop
cn.Close()
found something that works!
defined a binding source in code
then linked the listbox datasource to the binding source
then added following code :
Private Sub Onderzoeken_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Tbl_DossiersTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Dossiers)
Me.Tbl_OnderzoeksTypesTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_OnderzoeksTypes)
Dim dt = Tbl_OnderzoeksTypesBindingSource
cboxOnderzoek.DataSource = dt
cboxOnderzoek.DisplayMember = "OZ_TypeOnderzoek"
cboxOnderzoek.ValueMember = "OZ_ID"
rtbBeschrijvingOnderzoek.Text = dt(0)("OZ_TypeOnderzoek").ToString
cboxOnderzoek.Focus()
Private Sub CboxDiagnose_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboxOnderzoek.SelectionChangeCommitted
rtbBeschrijvingOnderzoek.Text = DirectCast(cboxOnderzoek.SelectedItem, DataRowView)("OZ_Onderzoeksbeschrijving").ToString
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb")
cn.Open()
Dim ssql As String = "Select Rel_ID, tbl_Relaties.Rel_Naam &' ' & Rel_Voornaam as totaleNaam " &
"From tbl_Relaties INNER Join (tbl_Dossiers INNER Join tbl_DossRelatie On " &
"tbl_Dossiers.Dos_ID = tbl_DossRelatie.DR_DossID) ON tbl_Relaties.Rel_ID = tbl_DossRelatie.DR_RelID WHERE OZ_ID = " & cboxOnderzoek.SelectedValue
Dim cmmd As New OleDb.OleDbCommand(ssql, cn)
Dim dr As OleDb.OleDbDataReader
dr = cmmd.ExecuteReader
If dr.HasRows Then
Application.DoEvents()
bs_Relaties.DataSource = dr
lboxOZpatientcombo.DisplayMember = "totaleNaam"
lboxOZpatientcombo.ValueMember = "Rel_ID"
End If
cn.Close()
End Sub
since i added a binding source, the rest was easier to do:
Private Sub lboxOZpatientcombo_DoubleClick(sender As Object, e As EventArgs) Handles lboxOZpatientcombo.DoubleClick
Try
Dim MPF As New MainPatientform
MPF.display(Me, bs_Relaties.Current("rel_id"))
Catch ex As Exception
End Try
End Sub
thanks to all for new insights in this matter.

How to get the row value of a ListView using the row number?

I'm new here and a VB.net newbie.
Is there any way that we can get row value and display it to a Label using a row number.
For example, if a number generated is 4, is there any code that could get the values from the very 4th row of the ListView item?
Sub Display_NameList()
Me.Name_ListView.Items.Clear()
CONNECTION.Close()
CONNECTION.Open()
Query = "Select * From name_listing Where Raffle_Indicator='1'"
comm = New MySqlCommand(Query, CONNECTION)
comm.ExecuteNonQuery()
Reader = comm.ExecuteReader
While Reader.Read
Dim lv As ListViewItem
lv = Name_ListView.Items.Add(Convert.ToString(Reader("ID") & ""))
lv.SubItems.Add(Convert.ToString(Reader("Name") & ""))
lv.SubItems.Add(Convert.ToString(Reader("Office") & ""))
End While
End Sub
An example for listbox
Public Class Form1
Dim codici As String() = {"cod1", "cod2", "cod3", "cod4", "cod5", "cod6"}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.DataSource = codici
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If Not (ListBox1.SelectedItem Is Nothing) Then
Label1.Text = ListBox1.SelectedItem.ToString
Else
MessageBox.Show("No selection")
End If
End Sub
End Class

How to display data in DataGridView like flight information display

I have a program that displays data from MS Access in DataGridView by Timers
I put 2 dgvs in my Form and each one should display different data from different tables.
my dgv displays 14 rows (that's the full size of monitor!).
here is what i tried:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
getDATA(dgv1, dgv2, Timer1, Timer2, "tab1")
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
getDATA(dgv2, dgv1, Timer2, Timer1, "tab2")
End Sub
Private Sub getDATA(dgv As DataGridView, vdgv As DataGridView, tm1 As Timer, tm2 As Timer, tbl As String)
Try
dgv.Visible = True
vdgv.Visible = False
If conn.State = ConnectionState.Open Then conn.Close()
Dim sqlstr As String = ""
sqlstr = "Select f1,f2,f3,f4 from " + tbl
Dim ds As New DataTable
Dim da As New OleDbDataAdapter(sqlstr, conn)
ds.Reset()
da = New OleDbDataAdapter(sqlstr, conn)
da.Fill(ds)
conn.Open()
If ds.Rows.Count = 0 Then
dgv.Rows.Clear()
Else
dgv.Rows.Clear()
dgv.Rows.Add(ds.Rows.Count)
For s = 0 To ds.Rows.Count - 1
dgv.Rows(s).Cells(0).Value = ds.Rows(s).Item("f1")
dgv.Rows(s).Cells(1).Value = ds.Rows(s).Item("f2")
dgv.Rows(s).Cells(2).Value = ds.Rows(s).Item("f3")
dgv.Rows(s).Cells(3).Value = ds.Rows(s).Item("f4")
Next s
End If
dgv.ClearSelection()
conn.Close()
tm1.Stop()
tm2.Start()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
This code is work fine, but sometimes one of the tables contains more than 14 rows!
how can i display the rest of rows in specific DGV?
should i use another Timer?