Imports System.Data.OleDb Public Class frmXem_Thong_Tin_Hop_Dong Private Sub Bo_Sung_cap_nhat_hop_dong_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'QLNuocDataSet.HopDong' table You can move, or remove it, as needed Me.HopDongTableAdapter.Fill(Me.QLNuocDataSet.HopDong) End Sub End Class Imports System.Data.OleDb Public Class BoSung_HopDong Private str As String = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Hà_thi kỹ nghề\Thuc_Hanh_VBnet\QLNuoc.accdb" Private cnn As OleDbConnection Private dt As New DataTable Private da As New OleDbDataAdapter Private cmd As New OleDbCommand Private Sub hienthi() cmd = cnn.CreateCommand cmd.CommandText = "Select * from hopdong" dt.Clear() da.SelectCommand = cmd da.Fill(dt) Dgvhopdong.DataSource = dt End Sub Private Sub BoSung_HopDong_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try cnn = New OleDbConnection(str) cnn.Open() hienthi() MessageBox.Show("Kết nối thành công !") Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub btnthemmoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthemmoi.Click 'Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click 'Tao row moi theo cấu trúc row dt Dim row As DataRow = dt.NewRow() row("SoHieuHD") = txtshd.Text row("TenChuHo") = txttenchuho.Text row("Phuong") = txtphuong.Text row("SoNha") = txtsonha.Text row("NgayBD") = DateTimePicker1.Text dt.Rows.Add(row) ' add row vào dt Dgvhopdong.DataSource = dt 'Tao command để update thay đổi vào file data nguồn Dim commandInsert As New OleDbCommand() commandInsert.Connection = cnn commandInsert.CommandType = CommandType.Text 'SQL for Insert commandInsert.CommandText = "Insert Into HopDong Values (@SoHieuHD,@TenChuHo,@Phuong,@SoNha,@NgayBD)" 'Nap tham so cho command commandInsert.Parameters.Add("@SoHieuHD", OleDbType.Numeric, 50, "SoHieuHD") ' Nạp giá trị cho tham số @STT thông qua giá trị cột nguồn STT commandInsert.Parameters.Add("@TenChuHo", OleDbType.VarChar, 50, "TenChuHo") commandInsert.Parameters.Add("@Phuong", OleDbType.VarChar, 50, "Phuong") commandInsert.Parameters.Add("@SoNha", OleDbType.VarChar, 50, "SoNha") commandInsert.Parameters.Add("@NgayBD", OleDbType.Date, 50, "NgayBD") 'Dùng da để áp đặt thay đổi vào File data nguồn da.InsertCommand = commandInsert 'gán command da.Update(dt) MessageBox.Show(" Cập nhật thành công!") End Sub Private Sub Dgvhopdong_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Dgvhopdong.CellClick Dim i As Integer i = Dgvhopdong.CurrentRow.Index txtshd.Text = Dgvhopdong.Item(0, i).Value txttenchuho.Text = Dgvhopdong.Item(1, i).Value txtphuong.Text = Dgvhopdong.Item(2, i).Value txtsonha.Text = Dgvhopdong.Item(3, i).Value DateTimePicker1.Text = Dgvhopdong.Item(4, i).Value End Sub Private Sub btnxoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnxoa.Click Dim check As Boolean cmd = cnn.CreateCommand cmd.CommandText = "Delete * from hopdong where SoHieuHD = " & txtshd.Text & "" Try check = cmd.ExecuteNonQuery If check Then MessageBox.Show("Xóa thành cơng ! ") hienthi() End If txtshd.Text = "" txttenchuho.Text = "" txtphuong.Text = "" txtsonha.Text = "" DateTimePicker1.Text = "" Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub btnsua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsua.Click 'Get Record can update Table Dim row As DataRow = dt.Select("SoHieuHD = '" & Convert.ToInt32(txtshd.Text) & "'")(0) 'Update row row.BeginEdit() row("TenChuHo") = txttenchuho.Text row("Phuong") = txtphuong.Text row("SoNha") = txtsonha.Text row("NgayBD") = DateTimePicker1.Text row.EndEdit() 'Tao command để update thay đổi vào file data nguồn Dim commandUpdate As New OleDbCommand() commandUpdate.Connection = cnn commandUpdate.CommandType = CommandType.Text 'SQL for Update commandUpdate.CommandText = "Update HopDong Set TenChuHo=@TenChuHo, Phuong=@Phuong, SoNha=@SoNha, NgayBD=@NgayBD Where SoHieuHD=@SoHieuHD" 'Nap tham so cho command commandUpdate.Parameters.Add("@TenChuHo", OleDbType.VarChar, 20, "TenChuHo") commandUpdate.Parameters.Add("@Phuong", OleDbType.VarChar, 20, "Phuong") commandUpdate.Parameters.Add("@SoNha", OleDbType.VarChar, 20, "SoNha") commandUpdate.Parameters.Add("@NgayBD", OleDbType.Date, 20, "NgayBD") commandUpdate.Parameters.Add("@SoHieuHD", OleDbType.Integer, 20, "SoHieuHD") 'Dùng da để áp đặt thay đổi vào File data nguồn da.UpdateCommand = commandUpdate 'gán command 'Dim a As New OleDbCommandBuilder(da) da.Update(dt) MessageBox.Show("Sửa ghi thành công !") End Sub Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click End End Sub End Class Public Class frmXem_thong_tin_tieu_thu Private Sub Xem_thong_tin_tieu_thu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'QLNuocDataSet4.Query4' table You can move, or remove it, as needed Me.Query4TableAdapter.Fill(Me.QLNuocDataSet4.Query4) 'ry2TableAdapter.Fill(Me.QLNuocDataSet2.Query2) End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click End Sub End Class Imports System.Data.DataTable Imports System.Data.OleDb Public Class frmnhaptieuthumoi Private Sub frmnhaptieuthumoi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TieuThuTableAdapter.Fill(Me.QLNuocDataSet.TieuThu) End Sub Private Sub btnthem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthem.Click TieuThuBindingSource.AddNew() End Sub Private Sub btnsua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsua.Click On Error GoTo saveErr Me.Validate() TieuThuBindingSource.EndEdit() TieuThuTableAdapter.Update(QLNuocDataSet.TieuThu) TieuThuTableAdapter.Fill(QLNuocDataSet.TieuThu) MessageBox.Show("Cập nhật thành công") saveErr: Exit Sub End Sub Private Sub btnxoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnxoa.Click TieuThuBindingSource.RemoveCurrent() TieuThuBindingSource.EndEdit() TieuThuTableAdapter.Update(QLNuocDataSet.TieuThu) TieuThuTableAdapter.Fill(QLNuocDataSet.TieuThu) MessageBox.Show("xóa thành cơng") End Sub Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click End End Sub End Class ... nguồn Dim commandInsert As New OleDbCommand() commandInsert.Connection = cnn commandInsert.CommandType = CommandType.Text 'SQL for Insert commandInsert.CommandText = "Insert Into HopDong Values... (@SoHieuHD,@TenChuHo,@Phuong,@SoNha,@NgayBD)" 'Nap tham so cho command commandInsert.Parameters.Add("@SoHieuHD", OleDbType.Numeric, 50, "SoHieuHD") ' Nạp giá trị cho tham số @STT thông qua giá trị cột nguồn STT commandInsert.Parameters.Add("@TenChuHo",... frmXem_thong_tin_tieu_thu Private Sub Xem_thong_tin_tieu_thu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'QLNuocDataSet4.Query4'