B
Blue man
Hello
I created a relation between 2 tables and that worked perfectly , but when i
added some parameters to select commands the relation didn't worked anymore.
here is the code befor adding that returns : " This constraint cannot be
enabled as not all values have corresponding parent values." what's wrong
with my code?
string comm="SELECT PN, FirstName, SurName, Gener FROM PersonalInfo WHERE
FirstName LIKE @FirstName OR SurName LIKE @SurName OR PN LIKE @PN";
string comm2="SELECT TableID, PN, Status, Type, Dosis, Time FROM
Medication";
adapter2.SelectCommand=new SqlCommand(comm2,myconn);
adapter.SelectCommand = new SqlCommand(comm, myconn);
adapter.SelectCommand.Parameters.Add("@FirstName",
SqlDbType.Char,50).Value="arash";
adapter.SelectCommand.Parameters.Add("@SurName",
SqlDbType.Char,50).Value="afaghi";
adapter.SelectCommand.Parameters.Add("@PN",SqlDbType.BigInt,8).Value=8989123
;
adapter2.Fill(ds,"Medication");
adapter.Fill(ds,"PersonalInfo");
ds.Tables["PersonalInfo"].PrimaryKey = new DataColumn[]
{ds.Tables["PersonalInfo"].Columns["PN"]};
ds.Tables["Medication"].PrimaryKey = new DataColumn []
{ds.Tables["Medication"].Columns["PN"]};
DataColumn PinfoPN = ds.Tables["PersonalInfo"].Columns["PN"];
DataColumn MedicPN = ds.Tables["Medication"].Columns["PN"];
DataRelation test = new DataRelation("Medication",PinfoPN,MedicPN);
ds.Relations.Add(test);
adapter.Fill(ds,"PersonalInfo");
adapter2.Fill(ds,"Medication");
dataGrid1.SetDataBinding(ds,"PersonalInfo");
Thanks in advance
I created a relation between 2 tables and that worked perfectly , but when i
added some parameters to select commands the relation didn't worked anymore.
here is the code befor adding that returns : " This constraint cannot be
enabled as not all values have corresponding parent values." what's wrong
with my code?
string comm="SELECT PN, FirstName, SurName, Gener FROM PersonalInfo WHERE
FirstName LIKE @FirstName OR SurName LIKE @SurName OR PN LIKE @PN";
string comm2="SELECT TableID, PN, Status, Type, Dosis, Time FROM
Medication";
adapter2.SelectCommand=new SqlCommand(comm2,myconn);
adapter.SelectCommand = new SqlCommand(comm, myconn);
adapter.SelectCommand.Parameters.Add("@FirstName",
SqlDbType.Char,50).Value="arash";
adapter.SelectCommand.Parameters.Add("@SurName",
SqlDbType.Char,50).Value="afaghi";
adapter.SelectCommand.Parameters.Add("@PN",SqlDbType.BigInt,8).Value=8989123
;
adapter2.Fill(ds,"Medication");
adapter.Fill(ds,"PersonalInfo");
ds.Tables["PersonalInfo"].PrimaryKey = new DataColumn[]
{ds.Tables["PersonalInfo"].Columns["PN"]};
ds.Tables["Medication"].PrimaryKey = new DataColumn []
{ds.Tables["Medication"].Columns["PN"]};
DataColumn PinfoPN = ds.Tables["PersonalInfo"].Columns["PN"];
DataColumn MedicPN = ds.Tables["Medication"].Columns["PN"];
DataRelation test = new DataRelation("Medication",PinfoPN,MedicPN);
ds.Relations.Add(test);
adapter.Fill(ds,"PersonalInfo");
adapter2.Fill(ds,"Medication");
dataGrid1.SetDataBinding(ds,"PersonalInfo");
Thanks in advance