Bai Tap Thuc Hanh Thuc Tap SQL
Bai Tap Thuc Hanh Thuc Tap SQL
Tạo class kết nối vào csdl SQL và hàm đọc, thủ tục ghi dữ
liệu:
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient
Sub HienThiDuLieu()
Try
Dim Str As String
Str = "select MaHang, TenLoai, TenHang, TenDVT from
HangHoa inner join LoaiHangHoa on HangHoa.MaLoai=LoaiHangHoa.MaLoai
left join DonViTinh on HangHoa.MaDVT=DonViTinh.MaDVT Where 1=1"
If (ckbTimTheoLoaiHang.Checked) Then
Str = Str + " AND HangHoa.MaLoai=" +
cmbTimTheoLoaiHang.SelectedValue.ToString()
End If
If ckbTimTheoTen.Checked Then
Str = Str + " AND TenHang like N'%" +
txtTimTheoTenHang.Text + "%'"
End If
DataGridView1.DataSource = objXuLyDuLieu.Doc(Str)
Catch ex As Exception
End Try
End Sub
Function KiemTraDuLieu()
If txtTenHang.Text = "" Then
Return False
Else
Return True
End If
End Function
cmbLoaiHang.SelectedIndex = 0
cmbDVT.SelectedIndex = 0
cmbTimTheoLoaiHang.SelectedIndex = 0
HienThiDuLieu()
Catch ex As Exception
End Try
End Sub
End If
End Sub
Catch
End Try
End Sub
Catch ex As Exception
End Try
End Sub
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.IO
Public Class frmNhanVien
Dim objXuLyDuLieu As New XuLyDuLieu
Public MaNV As String
Sub HienThiDuLieu()
DataGridView1.DataSource = objXuLyDuLieu.Doc("select *
from NhanVien")
End Sub
Function KiemTraDuLieu()
If txtHoTen.Text = "" Then
MsgBox("Bạn chưa nhập tên nv")
Return False
Else
Return True
End If
End Function
Private Sub frmNhanVien_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
HienThiDuLieu()
End Sub
Try
Dim mstr As New MemoryStream()
PictureBox1.Image.Save(mstr,
PictureBox1.Image.RawFormat)
Catch ex As Exception
End Try
End Sub