Imports System.Data.OleDb
Module Module1 Sub Main() Try ' Define a connection object Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=..\..\db.mdb") ' Create a data adapter to retrieve records from db Dim strSELECT As String = "SELECT ID AS UserID, fn AS FirstName, ln AS LastName, cty AS City, st AS State FROM tabUsers" Dim daUsers As New OleDbDataAdapter(strSELECT, dbConn) Dim dsUsers As New DataSet("Users") ' Fill the dataset daUsers.Fill(dsUsers) ' Go through the records and print them using the mapped names Dim r As DataRow For Each r In dsUsers.Tables(0).Rows Console.WriteLine("ID: {0}, FirstName: {1}, LastName: {2}, City: {3}, State: {4}", r("UserID"), r("FirstName"), r("LastName"), r("City"), r("State")) Next Catch ex As Exception ' An error occurred. Show the error message Console.WriteLine(ex.Message) End Try End Sub End Module '******************************************************************************************************************************************************************************* ' leggere il valore di un campo su una griglia Dim row As NorthwindDataSet.CustomersRow row = CType(CType(Me.CustomersBindingSource.Current, DataRowView).Row, NorthwindDataSet.CustomersRow) ' apre il form con il valore della ID My.Forms.CustomersForm.Show(row.CustomerID) '******************************************************************************************************************************************************************************* ' codice della form CustomerForm ' Copyright (c) Microsoft Corporation. All rights reserved. Public Class CustomersForm Private _customerIDValue As String Public Property CustomerID() As String Get Return _customerIDValue End Get Set(ByVal value As String) _customerIDValue = value End Set End Property Private Sub bindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Validate() Me.CustomersBindingSource.EndEdit() Me.CustomersTableAdapter.Update(Me.NorthwindDataSet.Customers) End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load LoadData() End Sub Public Sub LoadData() If Me.CustomerID.Trim().Length > 0 Then Me.CustomersTableAdapter.FillByCustomerID(Me.NorthwindDataSet.Customers, Me.CustomerID) End If End Sub Public Overloads Sub Show(ByVal customerId As String) Me.CustomerID = customerId LoadData() MyBase.Show() Me.BringToFront() End Sub End Class |