' senza importare nulla
' inserisce con ADD i valori in una listbox Inherits System.Windows.Forms.Form Private Sub frmMain_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim Connection As ADODB.Connection = New ADODB.Connection() Connection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\.." & "\Nwind.mdb;Persist Security Info=False") Dim RS As ADODB.Recordset = New ADODB.Recordset() RS.Open("SELECT * FROM Customers", _ Connection, _ ADODB.CursorTypeEnum.adOpenDynamic, _ ADODB.LockTypeEnum.adLockReadOnly, 0) While Not RS.EOF lbCustomers.Items.Add(RS.Fields("ContactName").Value & " From " & RS.Fields("CompanyName").Value) RS.MoveNext() End While RS.Close() Connection.Close() End Sub Sub Main() Dim cn As New ADODB.Connection() cn.ConnectionString = "provider=sqloledb;server=(localhost);database=northwind;uid=<username>" cn.Open() Dim rs As New ADODB.RecordSet() rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic rs.Open("select * from products", cn) rs.ActiveConnection = Nothing cn.Close() Dim da As New System.Data.OleDb.OleDbDataAdapter() Dim ds As New DataSet() da.Fill(ds, rs, "products") Console.Write("There are " & ds.Tables(0).Rows.Count.ToString & " total products.") Console.ReadLine() End Sub |