Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 18
  1. #1

    riempire un datagrid

    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
    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

  2. #2

    [VB.NET] riempire un datagrid

    scusatemi in VB.NET chiedo l'esempio.....

    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

  3. #3
    Utente di HTML.it L'avatar di Sypher
    Registrato dal
    Jun 2003
    Messaggi
    1,994
    Io userei un DataSet,il DataAdapter per riempirlo col metodo fill, poi al DataSource del DataGrid gli passi il Dataset!
    La passera non dura perchè Sypher la cattura!

    "No one like us we don't care, we are millwall, super millwall, we are millwall from the DEN"

  4. #4
    un esempio?????



    E grazie
    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

  5. #5
    Utente di HTML.it L'avatar di Sypher
    Registrato dal
    Jun 2003
    Messaggi
    1,994
    Lo stavo cercando!

    Dim DataSet1 as new DataSet
    Dim mySqlDataAdapter As OleDbDataAdapter
    mySqlDataAdapter = New OleDbDataAdapter("la tua select", latuaConnessione)
    mySqlDataAdapter.Fill(DataSet1,"NomeTuaTabellaNonN ecessario")
    Me.grdDataGrid.DataSource = DataSet1



    Non so se ho scritto bene perchè l'ho tradotto da c#, forse ho sbajato qualcosa nella creazione degli oggetti! Controlla!
    La passera non dura perchè Sypher la cattura!

    "No one like us we don't care, we are millwall, super millwall, we are millwall from the DEN"

  6. #6
    non va!!!!

    Ottengo questo errore

    Eccezione non gestita di tipo "System.NullReferenceException" in GestVerNet.exe

    Informazioni aggiuntive: Riferimento a un oggetto non impostato su un'istanza di oggetto.



    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

  7. #7
    Utente di HTML.it L'avatar di Sypher
    Registrato dal
    Jun 2003
    Messaggi
    1,994
    Originariamente inviato da g.scardigno
    non va!!!!

    Ottengo questo errore

    Eccezione non gestita di tipo "System.NullReferenceException" in GestVerNet.exe

    Informazioni aggiuntive: Riferimento a un oggetto non impostato su un'istanza di oggetto.



    :master: Quale riga ti da errore???
    La passera non dura perchè Sypher la cattura!

    "No one like us we don't care, we are millwall, super millwall, we are millwall from the DEN"

  8. #8
    questa:

    codice:
    Me.grdDataGrid.DataSource = DataSet1
    booooooooo

    credevo che fosse una cosa semplice.....
    invece.....
    grazie per la disponibilità...
    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

  9. #9
    Utente di HTML.it L'avatar di Sypher
    Registrato dal
    Jun 2003
    Messaggi
    1,994
    L'ho rifatto e provato in VB.Net, l'unica differenza col tuo è che io uso SqlServer, quindi:
    codice:
    conn.Open()
    Dim DataSet1 As New System.Data.DataSet()
    Dim mySqlDataAdapter As System.Data.SqlClient.SqlDataAdapter
    mySqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter("Select * from Clienti", conn)
    mySqlDataAdapter.Fill(DataSet1)
    DataGrid1.DataSource = DataSet1
    Dovrebbe funzionarti però...strano! :master:
    La passera non dura perchè Sypher la cattura!

    "No one like us we don't care, we are millwall, super millwall, we are millwall from the DEN"

  10. #10
    non va!!!!!

    ma che cavolo può essere....
    ma tu l'hai provato con un semplice db access?????
    Si Impara di più quando dobbiamo inventare!
    Il mio primo sito : www.assclima.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.