Member 11436716
весь код
Imports System.Data.OleDb
Public Class Form1
Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\web_database.accdb;Jet OLEDB:Database Password=kluytiaSDqwer3210549")
Dim DataSet1 As New DataSet
Dim BindingSource1 As BindingSource
Dim BindingSource2 As BindingSource
Dim DataAdapter1 As New OleDbDataAdapter
Sub conn()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT tb1.ID_mail ,tb1.clien_mail, tb1.model_mail, tb2.probl_acce,tb2.main_acce,tb2.typ_acce FROM tb1, tb2 where tb1.ID_mail = tb2.ID_acce", con)
con.Open()
DataAdapter1 = New OleDbDataAdapter(cmd)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(DataAdapter1)
DataSet1 = New DataSet()
DataAdapter1.Fill(DataSet1, "tb1,tb2")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "tb1,tb2"
con.Close()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
conn()
DataGridView1.Columns(0).ReadOnly = True
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Sort(DataGridView1.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
count()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub count()
On Error Resume Next
Dim records, current As Integer
records = BindingSource1.Count
current = BindingSource1.Position + 1
Label1.Text = current.ToString & " from " & records.ToString
End Sub
Private Sub delete_Click(sender As System.Object, e As System.EventArgs) Handles delete.Click
Try
If DataGridView1.RowCount <= 0 Then
Exit Sub
End If
DataGridView1.ClearSelection()
Dim a As Integer
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Selected = True
a = DataGridView1.Rows.GetLastRow(DataGridViewElementStates.Selected).ToString + 1
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
Validate()
DataGridView1.Refresh()
DataAdapter1.Update(DataSet1, "tb1,tb2")
DataSet1.AcceptChanges()
conn()
count()
MsgBox("ok", 64 + 524288, "delete")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub search_Click(sender As System.Object, e As System.EventArgs) Handles search.Click
Try
If IsNumeric(TextBox1.Text) = False Then
Dim DataAdapter As New OleDbDataAdapter("SELECT tb1.ID_mail ,tb1.clien_mail, tb1.model_mail, tb2.probl_acce,tb2.main_acce,tb2.typ_acce FROM tb1,tb2 where clien_mail LIKE '" & Trim$(TextBox1.Text) &
"%' or model_mail like '" & Trim$(TextBox1.Text) &
"%' or probl_acce like '" & Trim$(TextBox1.Text) &
"%' or main_acce like '" & Trim$(TextBox1.Text) &
"%' or typ_acce like '" & Trim$(TextBox1.Text) &
"%'", con)
con.Open()
DataSet1.Clear()
DataAdapter.Fill(DataSet1, "tb1,tb2")
con.Close()
If Me.BindingContext(DataSet1, "tb1,tb2").Count = 0 Then
TextBox1.Text = ""
con.Close()
Exit Sub
Else
DataSet1.Clear()
DataAdapter.Fill(DataSet1, "tb1,tb2")
count()
Exit Sub
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub save_Click(sender As System.Object, e As System.EventArgs) Handles save.Click
Try
Validate()
DataGridView1.Refresh()
DataAdapter1.Update(DataSet1, "tb1,tb2")
DataSet1.AcceptChanges()
conn()
count()
MsgBox("ok", 64 + 524288, "save")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class