Come si riesce a riempire un datagrid con una select...
Ho fatto questo...
ma non va dove sbaglio????
codice:Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Public cn As OleDbConnection #Region " Codice generato da Progettazione Windows Form " Public Sub New() MyBase.New() 'Chiamata richiesta da Progettazione Windows Form. InitializeComponent() 'Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent() End Sub 'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Richiesto da Progettazione Windows Form Private components As System.ComponentModel.IContainer 'NOTA: la procedura che segue è richiesta da Progettazione Windows Form. 'Può essere modificata in Progettazione Windows Form. 'Non modificarla nell'editor del codice. Friend WithEvents grdDataGrid As System.Windows.Forms.DataGrid Friend WithEvents Button1 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.grdDataGrid = New System.Windows.Forms.DataGrid Me.Button1 = New System.Windows.Forms.Button CType(Me.grdDataGrid, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'grdDataGrid ' Me.grdDataGrid.DataMember = "" Me.grdDataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.grdDataGrid.Location = New System.Drawing.Point(32, 104) Me.grdDataGrid.Name = "grdDataGrid" Me.grdDataGrid.Size = New System.Drawing.Size(632, 136) Me.grdDataGrid.TabIndex = 0 ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(192, 312) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(80, 40) Me.Button1.TabIndex = 1 Me.Button1.Text = "Button1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(720, 453) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.grdDataGrid) Me.Name = "Form1" Me.Text = "Form1" CType(Me.grdDataGrid, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Public ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" Public Sub Connetti(ByVal nomedb As String) cn = New OleDbConnection(ConnString & nomedb) 'Dichiaro la nuova connessione If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() 'MessageBox.Show("Connessione al db avvenuta correttamente") End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Connetti("F:\Scardigno1_4_2003\Gestione Verifiche\GestioneVerifiche\GestVer_vero.mdb") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sql1 As String Dim Provincia As String Provincia = "ba" sql1 = "SELECT * from impianti" Dim cmd As New OleDbCommand(sql1, cn) Dim dr As OleDbDataReader = cmd.ExecuteReader() Me.grdDataGrid.DataSource = dr.Read()?????????? End Sub End Class

Rispondi quotando


