Accesso ai dati in modalità disconnessa

mercoledì 10 aprile 2013 - 20.05

ReRosso Profilo | Junior Member

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
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 !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5