Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Bindare un datagridview tra Tabella e Query
giovedì 30 settembre 2010 - 14.54
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
PierLuigi69
Profilo
| Newbie
2
messaggi | Data Invio:
gio 30 set 2010 - 14:54
Salve a tutti avrei un quisito sa porVi.
Ho una tabella T_Articoli e una query Q_Articoli, la query è relazionata con una tabella Fornitori.
Quello che io devo fare e bindare nel form i dati della tabella con quella della query tramite ID_Articoli,
Praticamente nel form gestisco i dati con la tabella, per motivi di aggiornamento database, e nello stesso form
popolo un datagrid con la query che mi contiene anche il nome del fornitore.
Codice di caricamento e Binding del form:
Private myCurrencyManager As CurrencyManager
Public Sub Load(ByVal Tabella As String, ByVal Frm As Form, ByRef DA As SqlDataAdapter, ByRef DS As DataSet, ByRef DT As DataTable)
Dim CN As New SqlConnection
CN.ConnectionString = DBSTConnectionString
Dim SQL As String = Nothing
SQL = "SELECT * FROM " & Tabella
CN.Open()
DA = New SqlDataAdapter(SQL, CN)
DS = New DataSet
DA.Fill(DS, Tabella)
DT = DS.Tables(Tabella)
myCurrencyManager = CType(Frm.BindingContext(DT), CurrencyManager)
Dim N As Integer = 0
For N = 0 To DT.Columns.Count - 1
Dim Ctrl As Control = Nothing
For Each Ctrl In Frm.Controls
If TypeOf Ctrl Is TextBox Then
TXT = Ctrl
If TXT.Name = DT.Columns.Item(N).ColumnName Then
TXT.DataBindings.Add("Text", DT, DT.Columns.Item(N).ColumnName)
Exit For
End If
End If
If TypeOf Ctrl Is Label Then
LAB = Ctrl
If LAB.Name = DT.Columns.Item(N).ColumnName Then
LAB.DataBindings.Add("Text", DT, DT.Columns.Item(N).ColumnName)
Exit For
End If
End If
Next
Next
myCurrencyManager.Position = myCurrencyManager.Count - 1
CN.Close()
End Sub
Poi popolo il datagrid:
Public Sub Load_Dgv(ByVal Dgv As DataGridView, ByVal Query As String, ByVal DTOriginal As DataTable, ByVal DSM As DataSet)
Dim DA As SqlDataAdapter
Dim DS As DataSet
Dim DT As DataTable
Dim CN As New SqlConnection
CN.ConnectionString = DBSTConnectionString
Dim SQL As String = Nothing
SQL = "SELECT * FROM " & Query
DA = New SqlDataAdapter(SQL, CN)
DS = New DataSet
DA.Fill(DS, Query)
DT = DS.Tables(Query)
CN.Open()
Dgv.DataMember = "{ID_Articoli}"
Dgv.DataSource = DT
End Sub
Come posso bindare il Datagrid con la tabella??
E' un mese che sono fermo a questo punto non riesco a trovare niente a riguardo nel Web.
Potete aiutarmi?
PS: Spero di essere stato chiaro nel presentare il mio problema
#######################
Scusate ma non ho ricevuto nessuna risposta in merito in data 04/10/10, vorrei capire se è una questione di come Vi è stato
posto il problema o altro.
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !