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
ASP.NET 2.0 / 3.5 / 4.0
Accesso ai dati in modalità disconnessa
mercoledì 10 aprile 2013 - 20.05
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
ReRosso
Profilo
| Junior Member
67
messaggi | Data Invio:
mer 10 apr 2013 - 20:05
Ciao ragazzi,
Sto valutando l'accesso ai dati in modalità disconnessa.
779x158
31Kb
Ipotizzando una situazione del genere ho tentato il seguente codice:
SqlConnection cn = new SqlConnection(MD.Properties.Settings.Default.CN);
SqlCommand cmdCor = new SqlCommand();
SqlDataAdapter daCor= new SqlDataAdapter();
SqlCommand cmdDet = new SqlCommand();
SqlDataAdapter daDet = new SqlDataAdapter();
SqlCommand cmdStu = new SqlCommand();
SqlDataAdapter daStu = new SqlDataAdapter();
DataSet ds = new DataSet();
BindingSource bsCor = new BindingSource();
BindingSource bsDet = new BindingSource();
BindingSource bsStu = new BindingSource();
cmdCor.Connection = cn;
cmdCor.CommandType = CommandType.Text;
cmdCor.CommandText = "select * from corsi";
cmdDet.Connection = cn;
cmdDet.CommandType = CommandType.Text;
cmdDet.CommandText = "select * from DettaglioCorsi";
cmdStu.Connection = cn;
cmdStu.CommandType = CommandType.Text;
cmdStu.CommandText = "select * from Studenti";
daCor.SelectCommand = cmdCor;
daCor.Fill(ds, "Corso");
daDet.SelectCommand = cmdDet;
daDet.Fill(ds, "Dettaglio");
daStu.SelectCommand = cmdStu;
daStu.Fill(ds, "Studenti");
DataColumn parent = ds.Tables["Corso"].Columns["idCorso"];
DataColumn child = ds.Tables["Dettaglio"].Columns["corso"];
DataRelation rel = new DataRelation("CorDet", parent, child, false);
rel.Nested = true;
ds.Relations.Add(rel);
parent = ds.Tables["Dettaglio"].Columns["studente"];
child = ds.Tables["Studenti"].Columns["idStudente"];
rel = new DataRelation("StuDet", parent, child, false);
rel.Nested = true;
ds.Relations.Add(rel);
bsCor.DataSource = ds;
bsCor.DataMember = "Corso";
bsDet.DataSource = bsCor;
bsDet.DataMember = "CorDet";
bsStu.DataSource = bsDet;
bsStu.DataMember = "StuDet";
dgvCor.DataSource = bsCor;
dgvDett.DataSource = bsStu;
Il risultato finale è che la gridview "dettaglio" carica soltanto la prima voce di ogni singolo record "master".
Ho tentato anche di utilizzare i classici wizard di VS2010 ma ottengo lo stesso risultato
Avete suggerimenti?
Grazie
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 !