I am trying to create a relation between one parent table and three child tables. When I enter the code that I think is correct to build these realtions, I get "A relation already exist for these child columns". I have commented out some code that I thought was creating the problem but the problem still exist. Any insight to this error would be greatly appreciate.
Thanks
Kenny
Here is the code:
SqlDataAdapter sqlDA = CreateProviderAdapter();
SqlDataAdapter sqlDAphyins = CreateProviderInsAdapter()
;
SqlDataAdapter sqlDAphyspecial = CreateProviderSpecialAdapt
er();
SqlDataAdapter sqlDAphyspecialproc = CreateProviderSpecialProcA
dapter();
HDSDataSet.Clear();
sqlDA.FillSchema(HDSDataSe
t, SchemaType.Source);
sqlDA.Fill(HDSDataSet, "PROVIDER");
sqlDAphyins.Fill(HDSDataSe
t, "PHYS_INS_CARRIER");
sqlDAphyspecial.Fill(HDSDa
taSet, "PHYS_SPECIALTIES");
sqlDAphyspecialproc.Fill(H
DSDataSet,
"SPECIAL_PROCEDURES");
errormessage.Text = ProviderSearch;
errormessage2.Text = SearchProviderIns;
errormessage3.Text = SearchProvSpecialty;
// DataColumn[] keys = new DataColumn[1];
// keys[0] = HDSDataSet.Tables["PROVIDE
R"].Column
s["PHYSICI
AN_NPI"];
// HDSDataSet.Tables["PROVIDE
R"].Primar
yKey = keys;
// DataColumn[] key1 = new DataColumn[1];
// key1[0] = HDSDataSet.Tables["PHYS_IN
S_CARRIER"
].Columns[
"PHYSICIAN
_NPI"];
// HDSDataSet.Tables["PHYS_IN
S_CARRIER"
].PrimaryK
ey = key1;
// DataColumn[] key2 = new DataColumn[1];
// key2[0] = HDSDataSet.Tables["PHYS_SP
ECIALTIES"
].Columns[
"PHYSICIAN
_NPI"];
// HDSDataSet.Tables["PHYS_SP
ECIALTIES"
].PrimaryK
ey = key2;
// DataColumn[] key3 = new DataColumn[1];
// key3[0] = HDSDataSet.Tables["SPECIAL
_PROCEDURE
S"].Column
s["PHYSICI
AN_NPI"];
// HDSDataSet.Tables["SPECIAL
_PROCEDURE
S"].Primar
yKey = key3;
HDSDataSet.Relations.Add("
InsuranceR
elation", HDSDataSet.Tables["Provide
r"].Column
s["PHYSICI
AN_NPI"], HDSDataSet.Tables["PHYS_IN
S_CARRIER"
].Columns[
"PHYSICIAN
_NPI"]);--
----------
-<<<<<<<< ERROR OCCURS ON THIS LINE
HDSDataSet.Relations.Add("
Speciality
Relation",
HDSDataSet.Tables["Provide
r"].Column
s["PHYSICI
AN_NPI"], HDSDataSet.Tables["PHYS_SP
ECIALTIES"
].Columns[
"PHYSICIAN
_NPI"]);
HDSDataSet.Relations.Add("
SpecialPro
cRelation"
, HDSDataSet.Tables["Provide
r"].Column
s["PHYSICI
AN_NPI"], HDSDataSet.Tables["SPECIAL
_PROCEDURE
S"].Column
s["PHYSICI
AN_NPI"]);
Cache["HDS"] = HDSDataSet;
}
protected SqlDataAdapter CreateProviderAdapter()
{
SqlConnection conn = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand(ProviderSearch,
conn);
cmd.Parameters.Add(new SqlParameter("@SearchCity"
, txtSearchCity.Text));
cmd.Parameters.Add(new SqlParameter("@SearchState
", txtSearchState.Text));
cmd.Parameters.Add(new SqlParameter("@SearchZip",
txtSearchZip.Text));
SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
return sqlDA;
}
protected SqlDataAdapter CreateProviderInsAdapter()
{
SqlConnection connProvIns = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand(SearchProviderI
ns, connProvIns);
cmd.Parameters.Add(new SqlParameter("@SearchInsur
", txtSearchInsur.Text));
SqlDataAdapter sqlDAphyins = new SqlDataAdapter(cmd);
return sqlDAphyins;
}
protected SqlDataAdapter CreateProviderSpecialAdapt
er()
{
SqlConnection connPhysSpecial = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand(SearchProvSpeci
alty, connPhysSpecial);
cmd.Parameters.Add(new SqlParameter("@SearchSpeci
alty", txtSearchSpecial.Text));
SqlDataAdapter sqlDAphyspecial = new SqlDataAdapter(cmd);
return sqlDAphyspecial;
}
protected SqlDataAdapter CreateProviderSpecialProcA
dapter()
{
SqlConnection connPhysSpecialProc = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand(SearchProvSpeci
altyProc, connPhysSpecialProc);
cmd.Parameters.Add(new SqlParameter("@SearchSpeci
altyProc",
txtSearchSpecialProcCode.T
ext));
SqlDataAdapter sqlDAphyspecialproc = new SqlDataAdapter(cmd);
return sqlDAphyspecialproc;
}
private String ConnString
{
get
{
//HDS ConnectionString comes from the Web.Config
return ConfigurationManager.Conne
ctionStrin
gs["Chart RelayConnectionString"].Co
nnectionSt
ring;
}
}
private String ProviderSearch
{
get
{
String srchCmd = "Select PHYSICIAN_NPI, LAST_NAME, FIRST_NAME, ADDRESS_1, CITY, STATE, PHONE from Provider";
if (txtSearchCity.Text != "")
srchCmd += " where city = @SearchCity";
if(txtSearchState.Text != "")
srchCmd += " and STATE = @SearchState";
if (txtSearchZip.Text != "")
srchCmd += " and ZIP = @SearchZip";
srchCmd += " ORDER BY WEIGHT";
return srchCmd;
}
}
private String SearchProviderIns
{
get
{
String srchCmd = "Select * from PHYS_INS_CARRIER";
if (txtSearchInsur.Text != "")
srchCmd += " where INSURANCE_CARRIER_NAME = @SearchInsur";
return srchCmd;
}
}
private String SearchProvSpecialty
{
get
{
String srchCmd = "Select * from PHYS_SPECIALITIES";
if(txtSearchSpecial.Text != "")
srchCmd += " where DESCRIPTION = @SearchSpecialty";
return srchCmd;
}
}
private String SearchProvSpecialtyProc
{
get
{
String srchCmd = "Select * from SPECIAL_PROCEDURES";
if (txtSearchSpecialProcCode.
Text != "")
srchCmd += " where CPT = @SearchSpecialtyProc";
if (txtSearchSpecialProcDesc.
Text != "")
srchCmd += " where DESCRIPTION = @SearchSpecialtyProc";
return srchCmd;
}
}