Hi,
I have the following code, which works perfect, when I makes af DataGridView with drag and drop (the code pass over the FakturaId to the new form, so I can make a select on this)
System.Data.DataRowView SelectedRowView;
fakturasystemDataSet.FakturaRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)fakturaBindingSource.Current;
SelectedRow = (fakturasystemDataSet.FakturaRow)SelectedRowView.Row;
FakturaVis FakturaVisForm = new FakturaVis();
FakturaVisForm.LoadFakturaVis(SelectedRow.FakturaID);
FakturaVisForm.Show();
But now I have made my own dataset and adapter and I have some problems with the above code. I don't know, how I get the FakturaRow in intellisense (how I get this into the code, where I instansiate the dataset and the adapter)?
Is my dsView the same as, the system generated fakturaBindingSource?
My code where I instansiate the dataset and the adapters:
private void loadKundeFaktura()
{
//create a connection string to the access database
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;
User Id=password=;
Data Source=" + myDB);
// Create the DataSet
ds = new DataSet("KundeFaktura");
// Fill the Dataset with Kunder, map Default Tablename
// "Table" to "Kunder".
da1 = new OleDbDataAdapter("SELECT KundeId, Navn, Adresse, Postnr, Byen,
Telefonnr, Mobilnr, EmailAdr, Noter FROM Kunder", cn);
da1.TableMappings.Add("Table", "Kunder");
da1.Fill(ds);
// Fill the Dataset with Faktura, map Default Tablename
// "Table" to "Faktura". ORDER BY FakturaID DESC
da2 = new OleDbDataAdapter("SELECT FakturaID, KundeID, Dato, BetalingsDato,
Betalt FROM Faktura ORDER BY FakturaID DESC", cn);
da2.TableMappings.Add("Table", "Faktura");
da2.Fill(ds);
// Establish the Relationship "RelOrdDet"
// between Kunder ---< [Faktura]
System.Data.DataRelation relOrdDet;
System.Data.DataColumn colMaster2;
System.Data.DataColumn colDetail2;
colMaster2 = ds.Tables["Kunder"].Columns["KundeId"];
colDetail2 = ds.Tables["Faktura"].Columns["KundeID"];
relOrdDet = new System.Data.DataRelation("RelOrdDet", colMaster2,
colDetail2);
ds.Relations.Add(relOrdDet);
// The DataViewManager returned by the DefaultViewManager
// property allows you to create custom settings for each
// DataTable in the DataSet.
dsView = ds.DefaultViewManager;
// Databinding for the Grid's
dgrKunder.DataSource = dsView;
dgrKunder.DataMember = "Kunder";
dgrFaktura.DataSource = dsView;
dgrFaktura.DataMember = "Kunder.RelOrdDet";
}
Kind regards,
simsen :-)
I have the following code, which works perfect, when I makes af DataGridView with drag and drop (the code pass over the FakturaId to the new form, so I can make a select on this)
System.Data.DataRowView SelectedRowView;
fakturasystemDataSet.FakturaRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)fakturaBindingSource.Current;
SelectedRow = (fakturasystemDataSet.FakturaRow)SelectedRowView.Row;
FakturaVis FakturaVisForm = new FakturaVis();
FakturaVisForm.LoadFakturaVis(SelectedRow.FakturaID);
FakturaVisForm.Show();
But now I have made my own dataset and adapter and I have some problems with the above code. I don't know, how I get the FakturaRow in intellisense (how I get this into the code, where I instansiate the dataset and the adapter)?
Is my dsView the same as, the system generated fakturaBindingSource?
My code where I instansiate the dataset and the adapters:
private void loadKundeFaktura()
{
//create a connection string to the access database
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;
User Id=password=;
Data Source=" + myDB);
// Create the DataSet
ds = new DataSet("KundeFaktura");
// Fill the Dataset with Kunder, map Default Tablename
// "Table" to "Kunder".
da1 = new OleDbDataAdapter("SELECT KundeId, Navn, Adresse, Postnr, Byen,
Telefonnr, Mobilnr, EmailAdr, Noter FROM Kunder", cn);
da1.TableMappings.Add("Table", "Kunder");
da1.Fill(ds);
// Fill the Dataset with Faktura, map Default Tablename
// "Table" to "Faktura". ORDER BY FakturaID DESC
da2 = new OleDbDataAdapter("SELECT FakturaID, KundeID, Dato, BetalingsDato,
Betalt FROM Faktura ORDER BY FakturaID DESC", cn);
da2.TableMappings.Add("Table", "Faktura");
da2.Fill(ds);
// Establish the Relationship "RelOrdDet"
// between Kunder ---< [Faktura]
System.Data.DataRelation relOrdDet;
System.Data.DataColumn colMaster2;
System.Data.DataColumn colDetail2;
colMaster2 = ds.Tables["Kunder"].Columns["KundeId"];
colDetail2 = ds.Tables["Faktura"].Columns["KundeID"];
relOrdDet = new System.Data.DataRelation("RelOrdDet", colMaster2,
colDetail2);
ds.Relations.Add(relOrdDet);
// The DataViewManager returned by the DefaultViewManager
// property allows you to create custom settings for each
// DataTable in the DataSet.
dsView = ds.DefaultViewManager;
// Databinding for the Grid's
dgrKunder.DataSource = dsView;
dgrKunder.DataMember = "Kunder";
dgrFaktura.DataSource = dsView;
dgrFaktura.DataMember = "Kunder.RelOrdDet";
}
Kind regards,
simsen :-)
AnjaPosted Jul 24, 2006, 4:44 PM
I did it this way:
Form1's code:
private void btnFakturaVis_Click(object sender, EventArgs e)
{
//Her får jeg fat i den række jeg står på, på det pågældende gridview
CurrencyManager cm = this.BindingContext[dgrFaktura.DataSource,
dgrFaktura.DataMember] as CurrencyManager;
DataRowView rowView = cm.Current as DataRowView;
//Her tildeler jeg FakturaID til id
string id = rowView["FakturaID"].ToString();
//Her instansierer jeg min form2 med den id jeg har tildelt
FakturaVisForm = new FakturaVis(id);
FakturaVisForm.Show();
}
Form2's code:
public partial class FakturaVis : Form
{
string id;
public FakturaVis(string id)
{
InitializeComponent();
this.id = id;
}
private void FakturaVis_Load(object sender, EventArgs e)
{
txtID.Text = id;
}
}
AnjaPosted Jul 24, 2006, 2:00 AM
I will try to express myself in another way:
I have to pass the Id to another form.
Normally I would do it this way: I drag and drop a datagridview (AND use the Visual Studios wizard to make the connection and so on) into form1 and then I use the below code1 on a button, to pass the id with it.
But my problem is (I'm a very newbee), I tried instead of using the wizard to make my own connection to the database and put data into the datagridview. See code2.
Now I don't know what I shall do, to pass the id over to form2. On form2 I have som fields, which i also get from the database - but I cann't get them, don't have have the id.
Kind regards,
simsen :-)
Code1:
System.Data.DataRowView SelectedRowView;
fakturasystemDataSet.FakturaRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)fakturaBindingSource.Current;
SelectedRow = (fakturasystemDataSet.FakturaRow)SelectedRowView.Row;
FakturaVis FakturaVisForm = new FakturaVis();
FakturaVisForm.LoadFakturaVis(SelectedRow.FakturaID);
FakturaVisForm.Show();
Code2
private void loadKundeFaktura()
{
//create a connection string to the access database
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;
User Id=password=;
Data Source=" + myDB);
// Create the DataSet
ds = new DataSet("KundeFaktura");
// Fill the Dataset with Kunder, map Default Tablename
// "Table" to "Kunder".
da1 = new OleDbDataAdapter("SELECT KundeId, Navn, Adresse, Postnr, Byen,
Telefonnr, Mobilnr, EmailAdr, Noter FROM Kunder", cn);
da1.TableMappings.Add("Table", "Kunder");
da1.Fill(ds);
// Fill the Dataset with Faktura, map Default Tablename
// "Table" to "Faktura". ORDER BY FakturaID DESC
da2 = new OleDbDataAdapter("SELECT FakturaID, KundeID, Dato, BetalingsDato,
Betalt FROM Faktura ORDER BY FakturaID DESC", cn);
da2.TableMappings.Add("Table", "Faktura");
da2.Fill(ds);
// Establish the Relationship "RelOrdDet"
// between Kunder ---< [Faktura]
System.Data.DataRelation relOrdDet;
System.Data.DataColumn colMaster2;
System.Data.DataColumn colDetail2;
colMaster2 = ds.Tables["Kunder"].Columns["KundeId"];
colDetail2 = ds.Tables["Faktura"].Columns["KundeID"];
relOrdDet = new System.Data.DataRelation("RelOrdDet", colMaster2,
colDetail2);
ds.Relations.Add(relOrdDet);
// The DataViewManager returned by the DefaultViewManager
// property allows you to create custom settings for each
// DataTable in the DataSet.
dsView = ds.DefaultViewManager;
// Databinding for the Grid's
dgrKunder.DataSource = dsView;
dgrKunder.DataMember = "Kunder";
dgrFaktura.DataSource = dsView;
dgrFaktura.DataMember = "Kunder.RelOrdDet";
}