Date: 10/19/06 (C Sharp) Keywords: database, sql, web, microsoft private string ConnectionString; private DataViewManager dsView; private DataViewManager dsViewHospitals; private DataSet ds; public TestHospitalFormGrid() { InitializeComponent(); ConnectionString = "data source=edison;uid=sa;password=nothing;database=hospratestest"; SqlConnection cn = new SqlConnection(ConnectionString); //Create the DataSet ds = new DataSet("HospRates"); //Fill the dataset with hospitals SqlDataAdapter da1 = new SqlDataAdapter("select * from hospitals", cn); da1.TableMappings.Add("Table", "Hospitals"); da1.Fill(ds, "Hospitals"); //Fill the dataset with rates SqlDataAdapter da2 = new SqlDataAdapter("select * from CombinedRateData", cn); da2.TableMappings.Add("Table", "Rates"); da2.Fill(ds, "Rates"); //tables father back will go here later //Establish relatinship between hospitals and rates DataRelation relHospRates; DataColumn MasterColumn; DataColumn DetailColumn; MasterColumn = ds.Tables["Hospitals"].Columns["ID"]; DetailColumn = ds.Tables["Rates"].Columns["prov_id"]; relHospRates = new DataRelation("HospRatesRelation", MasterColumn, DetailColumn); ds.Relations.Add(relHospRates); dsView = ds.DefaultViewManager; dsViewHospitals = ???; dgDetail.DataSource = dsView; dgDetail.DataMember = "Rates.HospRatesRelation"; //dgDetail.DataSource = "Rates.HospRatesRelation"; cboName.DataSource = dsView; cboName.DisplayMember = "Hospitals.Name"; cboName.ValueMember = "Hospitals.ID"; } } This code generates an error. After two hours of looking around the web, I finally got pointed to this KB article, which tells me my problem stems from the fact that my DataMember has a period in it, and that this bug is considered a "feature" by Microsoft. As you can see, I have tried setting the datasource directly to the relation; this results in the form loading and the datagrid remaining empty no matter what I do. I need to find a way to set the datasource of the datagrid to the relation in question. It seems to me that the easiest way to do this will be to set the view dsViewHospitals to only show the relation in the dataset, but I'm not finding any code samples for how to set view to anything other than DefaultViewManager programmatically at Microsoft. How would I go about doing such a thing? Thanks.
|