ok ci ho messo un po' e ho risolto :
sia modificando il codice autocompilato da vb2010
sia andando a programmarlo a mano (più comodo e semplice)
per lo "spirito" del forum che prevede l'aiuto degli utenti (anche se in questa sezione non ne ho ricevuto molto) pubblico la mia soluzione
ovvio che uno per riuscire a sfruttarla dovrà studiarsela e fare tanta ricerca su google ma almeno questa è una base funzionante con vb2010 (e non è poco -.-)
classe form3
codice:
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form2.Visible = False
Me.prova.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Me.prova.MultiSelect = False
Dim sorgente As String
Dim strconn As String
Dim query As String
sorgente = "C:\test\agenda.mdb"
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sorgente
Dim conn As New OleDb.OleDbConnection(strconn) 'Creo una connessione al database
conn.Open() 'Apro la connessione al database
Dim ds As New DataSet 'Creo un oggetto che serve a rappresentare i dati del database in memoria tramite tabelle e relazioni
Dim riga As DataRow
query = "SELECT * FROM"
query = query & " nome"
query = query & " WHERE "
If My.Application.OpenForms.Item("Form2").Controls("nome").Text <> "" Then
query = query & "nome='" & My.Application.OpenForms.Item("Form2").Controls("nome").Text & "' AND "
End If
If My.Application.OpenForms.Item("Form2").Controls("cognome").Text <> "" Then
query = query & "cognome='" & My.Application.OpenForms.Item("Form2").Controls("cognome").Text & "' AND "
End If
If My.Application.OpenForms.Item("Form2").Controls("indirizzo").Text <> "" Then
query = query & "indirizzo='" & My.Application.OpenForms.Item("Form2").Controls("indirizzo").Text & "' AND "
End If
If My.Application.OpenForms.Item("Form2").Controls("telefono").Text <> "" Then
query = query & "tel='" & My.Application.OpenForms.Item("Form2").Controls("telefono").Text & "' AND "
End If
If My.Application.OpenForms.Item("Form2").Controls("fax").Text <> "" Then
query = query & "fax='" & My.Application.OpenForms.Item("Form2").Controls("fax").Text & "' AND "
End If
If My.Application.OpenForms.Item("Form2").Controls("email").Text <> "" Then
query = query & "email='" & My.Application.OpenForms.Item("Form2").Controls("email").Text & "' AND "
End If
query = query & "1=1 ORDER BY nome ASC, cognome ASC"
Dim comando1 As New OleDb.OleDbDataAdapter(query, conn)
'Creo un oggetto che serve a eseguire istruzioni in linguaggio Sql sul database
comando1.Fill(ds) 'Eseguo l'istruzione e riempio il DataSet che servirà a contenere i dati estratti dalla query
Dim lista = New List(Of Utente)
For Each riga In ds.Tables(0).Rows
lista.Add(New Utente With {.id = riga(0).ToString(), .Nome = riga(1).ToString(), .Cognome = riga(2).ToString(), .Indirizzo = riga(3).ToString(), .tel = riga(4).ToString(), .fax = riga(5).ToString(), .email = riga(6).ToString()})
Next
conn.Close() 'Chiudo la connessione al database
Me.prova.DataSource = lista
End Sub
End Class
classe utente
codice:
Public Class Utente
Private _id As String
Public Property id() As String
Get
Return Me._id
End Get
Set(ByVal value As String)
Me._id = value
End Set
End Property
Private _Nome As String
Public Property Nome() As String
Get
Return Me._Nome
End Get
Set(ByVal value As String)
Me._Nome = value
End Set
End Property
Private _Cognome As String
Public Property Cognome() As String
Get
Return Me._Cognome
End Get
Set(ByVal value As String)
Me._Cognome = value
End Set
End Property
Private _Indirizzo As String
Public Property Indirizzo() As String
Get
Return Me._Indirizzo
End Get
Set(ByVal value As String)
Me._Indirizzo = value
End Set
End Property
Private _tel As String
Public Property tel() As String
Get
Return Me._tel
End Get
Set(ByVal value As String)
Me._tel = value
End Set
End Property
Private _fax As String
Public Property fax() As String
Get
Return Me._fax
End Get
Set(ByVal value As String)
Me._fax = value
End Set
End Property
Private _email As String
Public Property email() As String
Get
Return Me._email
End Get
Set(ByVal value As String)
Me._email = value
End Set
End Property
End Class
non penso sia la soluzione migliore, ma io in internet non sono riuscito a trovarne nemmeno funzionanti
chiedo a chi è più esperto di indicarmi una soluzione più comoda
ciao
Grambo
ps: alla datagrid ho assegnato il nome prova