BLOG ĐANG TRONG THỜI GIAN PHÁT TRIỂN, MONG SỰ QUAN TÂM CỦA MỌI NGƯỜI DÀNH CHO BLOG MỚI NÀY CỦA HUNG.PRO.VN

CREATE DATA VIEWING CONTROLS IN VB.NET

CREATE DATA VIEWING CONTROLS IN VB.NET, TẠO CÁC ĐIỀU KHIỂN DUYỆT XEM DỮ LIỆU TRONG VB.NET
2 min read

 Hi mọi người, sau một ngày buồn mình lục lọi anh google về tìm hiểu những thủ thuật lập trình "VISUAL BASIC" xem có gì mới không, mình thấy có bài viết này cũng khá hay về việc lưu dữ liệu :D. 

VB.NET sử dụng thuộc tính BindingContext của form để lưu trữ các thông tin về các DataSet đang làm việc, để truy cập tới bảng cụ thế, dùng tên DataSet và tên bảng đang sử dụng làm tham số cho thuộc tính này.
Thuộc tính Position quy định vị trí của bản ghi hiện tại (đánh số từ 0).
Chẳng hạn, đoạn code sau đây thực hiện việc duyệt qua các bản ghi:
 Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
    Me.BindingContext(DataSet11, "KhachHang").Position += 1
End Sub

Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
    Me.BindingContext(DataSet11, "KhachHang").Position -= 1
End Sub

Ngoài ra, có thể sử dụng câu lệnh để thực hiện kết nối và làm việc với CSDL thông qua các đối tượng Connection, DataAdapter, DataSet..., duyệt qua các bản ghi, cập nhật dữ liệu vào CSDL như ví dụ dưới đây:

Mã lệnh của form:
 
 Public Class KhachHang2
    Dim vitri As Integer
    Dim kn As New OleDb.OleDbConnection
    Dim da As OleDb.OleDbDataAdapter
    Dim ds As New DataSet

    Private Sub KhachHang2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        kn.ConnectionString= "Provider=Microsoft.Jet.Oledb.4.0; Data Source = baitap.mdb"
        kn.Open()
        da = New OleDb.OleDbDataAdapter("select * from KhachHang", kn)
        da.Fill(ds, "KH")
        vitri = 0
        hienthi(vitri)
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        vitri = vitri + 1
        hienthi(vitri)
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        vitri = vitri - 1
        hienthi(vitri)
    End Sub

    Private Sub hienthi(ByVal vt As Integer)
        txtMaKH.Text = ds.Tables(0).Rows(vt).Item(0).ToString()
        txtTenKH.Text = ds.Tables(0).Rows(vt).Item(1).ToString()
        txtDiaChi.Text = ds.Tables(0).Rows(vt).Item(2).ToString()
        txtDienThoai.Text = ds.Tables(0).Rows(vt).Item(3).ToString()
    End Sub
End Class

Chúc các bạn thành công với thủ thuật đơn giản, và để tạo cho bản thân một chương trình lưu dữ thứ quan trọng của bản thân. :D
Theo : TinHoc88

Bạn có thể thích những bài đăng này

  • Hello everyone, with this "GET IP ADRESSBAR" algorithm, there is a lot of sharing on "INTERNET", but today Hung shares it with everyone, afraid people will forg…
  • Like the previous applications are applications that I wrote a long time ago and stored on the host :D Now looking back, should I make an application for you to test? :v You visit …
  • This is an application developed by me guys ^^. Also because I have too much free time, I can't wait to find the code, who would have thought I could write this application ^^ …
  • Today I would like to introduce to you the CMD application that I programmed myself ^^~, it is similar to the CMD of the computer, but in the shop, I can't open CMD but there a…
  • Playing games can be for fun, but hacking games is also to know your level :3 :)) Today I would like to guide you to create your own hack. For personal use :D I chose Kingdom Crus…
  • Today I would like to guide you to write an application that displays "TASK MANAGER" to serve you outside the NET shop, because outside the shop, it always blocks "T…

4 nhận xét

  1. second ago
    cũng hay nhưng k biết file .mdb đó là file gì trên windows?
  2. second ago
    m` cũng k tìm hiểu nhiều nhưng là một dạng file database trên windows bạn, và nó làm việc ở chế độ offline.
  3. second ago
    để m` tìm hiểu google chương trình đó là gì ? có phải execl k nhỉ :?
  4. second ago
    microsoft access bạn nhe.
Hung Pro Blog @ 2025
Chia sẽ kiến thức và tư duy sáng tạo về nhiều ngôn ngữ lập trình khác nhau. Csharp, Visual Studio, Blogger, HTML, Javascript, CSS..v.v
Developed by Jago Desain