Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A Relation named 'Patient' already belongs to this DataSet.  How do you get a duplicate relation when only one relation is configured?

Posted on 2008-10-24
4
Medium Priority
?
1,404 Views
Last Modified: 2010-04-21
I am trying to setup a relation between two tables but keep getting this error message trapped.

A Relation named 'Patient' already belongs to this DataSet.

Can someone point me in the right direction?

Here is my code:
----------------------------------------------------------------------------------------------------------------------------------------------

protected void btnPreAuthSearch_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
    {
        bool authenticated;
            authenticated = Convert.ToBoolean(Session["authenticated"]);
            
            
            if (authenticated)
            {
                  PopulatePatientDS();
                  this.PreAuthWebGrid1.DataSource = HDSDataSet.Tables["Patient"];
                  this.PreAuthWebGrid1.DisplayLayout.AutoGenerateColumns = false;
                  PreAuthWebGrid1.DisplayLayout.Bands.Clear();
                  this.PreAuthWebGrid1.DataBind();
            }

      }

      //------------   Patient Search Tab
      public DataSet HDSDataSet
      {
            get
            {
                  if (Cache["HDSDataSet"] == null)
                        Cache["HDSDataSet"] = new DataSet("HDSDataSet");

                  return (DataSet)Cache["HDSDataSet"];
            }
      }
      //------------   Patient Search Tab
      protected void PopulatePatientDS()
      {
            SqlDataAdapter sqlDA = CreatePatientAdapter();
        SqlDataAdapter sqlDAPreAuth = CreatePreAuthAdapter();
            HDSDataSet.Clear();
            sqlDA.FillSchema(HDSDataSet, SchemaType.Source);
            sqlDA.Fill(HDSDataSet, "Patient");
        sqlDAPreAuth.Fill(HDSDataSet, "Pre_Auth");

        try
        {
            HDSDataSet.Relations.Add("Patient",---------------------------------------------------DATA RELATION SET HERE   ---------------------------------
                HDSDataSet.Tables["Patient"].Columns["MPI"],
                HDSDataSet.Tables["Pre_Auth"].Columns["MPI"]);
        }
        catch (System.Exception x)
        {
            string s = x.Message;-----------------------------------------------------------------------ERROR is TRAPPED HERE  ----------------------------
            string m = s;
        }

       
    }



      //------------   Patient Adapter
      protected SqlDataAdapter CreatePatientAdapter()
      {

        string physicianNPI;
        physicianNPI = Session["physicianNPI"].ToString();

            SqlConnection conn = new SqlConnection(ConnString);
            SqlCommand cmd = new SqlCommand(SearchString, conn);
        cmd.Parameters.Add("@REFERRING_PROVIDER_NPI", SqlDbType.VarChar).Value = physicianNPI;
        cmd.Parameters.Add(new SqlParameter("@SearchFn", tbPreAuthFname.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchLn", tbPreAuthLname.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchAddress", tbPreAuthAddress.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchDOB", tbPreAuthDOB.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchSSN", tbPreAuthSSN.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchDL", tbPreAuthDL.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchPhn", tbPreAuthPhone.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchBillingId", tbPreAuthAccountNum.Text));
        cmd.Parameters.Add(new SqlParameter("@SearchSex", tbPreAuthSex.Text));


            SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
            return sqlDA;
      }

      //------------   Patient Search Tab
      private String ConnString
      {
            get
            {
                  //HDS ConnectionString comes from the Web.Config
                  return ConfigurationManager.ConnectionStrings["123121ConnectionString"].ConnectionString;

            }
      }

      //------------   Patient Search Tab
      private String SearchString
      {
            get
            {
            String srchCmd = "SELECT PATIENT.MPI, PATIENT.LAST_NAME, PATIENT.FIRST_NAME, PRIMARY_INSURANCE.PLAN_NAME, PATIENT.DATE_OF_BIRTH, PATIENT.SEX FROM PATIENT LEFT JOIN PRIMARY_INSURANCE ON PATIENT.MPI = PRIMARY_INSURANCE.MPI WHERE PATIENT.LAST_NAME = @SearchLn OR PATIENT.FIRST_NAME = @SearchFn";
                  return srchCmd;

            }
    }



    //------------   PreAuthAdapter
    protected SqlDataAdapter CreatePreAuthAdapter()
    {

        SqlConnection conn = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(PreAuthSearchString, conn);
        SqlDataAdapter sqlDAPreAuth = new SqlDataAdapter(cmd);
        return sqlDAPreAuth;
    }

   

    //------------   PreAuth Search Command
    private String PreAuthSearchString
    {
        get
        {
            String srchCmd = "SELECT PRE_AUTH.MPI, PRE_AUTH.INSURANCE_NAME, PRE_AUTH.PRE_AUTH_NUM, PRE_AUTH.EXPIRY_DATE, PRE_AUTH.VISITS FROM PRE_AUTH";
            return srchCmd;

        }
    }


0
Comment
Question by:kwh3856
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
jgordos earned 2000 total points
ID: 22798730
SqlDataAdapter sqlDA = CreatePatientAdapter();
SqlDataAdapter sqlDAPreAuth = CreatePreAuthAdapter();
HDSDataSet.Clear();
sqlDA.FillSchema(HDSDataSet, SchemaType.Source);
sqlDA.Fill(HDSDataSet, "Patient");                                           <------------ You added PATIENT here....
sqlDAPreAuth.Fill(HDSDataSet, "Pre_Auth");
try
{
HDSDataSet.Relations.Add("Patient",                                    
HDSDataSet.Tables["Patient"].Columns["MPI"],                          <------------- And again, here...
HDSDataSet.Tables["Pre_Auth"].Columns["MPI"]);
}


0
 

Author Comment

by:kwh3856
ID: 22811711
jgordos,
If I do not do the .fill on the table then when I look at my dataset there are no records on the table.  Is there some other way to accomplish this task?

Thanks
Kenny
0
 

Author Comment

by:kwh3856
ID: 22826949
Resolved Problem with the remove command.  I think the actual problem was due to caching.
 

protected void PopulatePatientDS()
{
SqlDataAdapter sqlDA = CreatePatientAdapter();
SqlDataAdapter sqlDAPreAuth = CreatePreAuthAdapter();
HDSDataSet.Clear();
sqlDA.FillSchema(HDSDataSet, SchemaType.Source);
sqlDA.Fill(HDSDataSet, "Patient");
sqlDAPreAuth.Fill(HDSDataSet, "Pre_Auth");
 

try
{
HDSDataSet.Relations.Remove("PatientRelation"); ------------------------------------------------Fixed problem-------------------------------
HDSDataSet.Relations.Add("PatientRelation",
HDSDataSet.Tables["Patient"].Columns["MPI"],
HDSDataSet.Tables["Pre_Auth"].Columns["MPI"]);
}
catch (System.Exception x)
{
string s = x.Message;
string m = s;
}
 
this.PreAuthWebGrid1.DataSource = HDSDataSet.Tables["Patient"];
this.PreAuthWebGrid1.DisplayLayout.AutoGenerateColumns = false;
PreAuthWebGrid1.DisplayLayout.Bands.Clear();
this.PreAuthWebGrid1.DataBind();


 
0
 

Author Closing Comment

by:kwh3856
ID: 31509744
jgordos,
I resolved the problem whith the remove command.  I wanted to award you the points for trying to help me.  Thanks for your assistance.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question