[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Must declare the scalar variable "@SearchCity"

Posted on 2007-11-20
10
Medium Priority
?
626 Views
Last Modified: 2010-04-21
I am attempting to fill the schema in a data set and keep getting a "Must declare the scalar variable "@SearchCity".  The problem is that I think I have already defined the variable.  Can anyone see what I am missing.  Here is my code.

Thanks
Kenny


  protected SqlDataAdapter CreateProviderAdapter()
    {
        SqlConnection conn = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(ProviderSearch, conn);

        if
            (txtSearchCity.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchCity", txtSearchCity.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchCity", string.Empty));
               
        if
            (txtSearchState.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchState", txtSearchState.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchState", string.Empty));

        if (txtSearchZip.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchZip", txtSearchZip.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchZip", string.Empty));

       
        SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
        sqlDA.FillSchema(HDSDataSet, SchemaType.Mapped, "PROVIDER");
        sqlDA.Fill(HDSDataSet, "PROVIDER");

        return sqlDA;
    }

    private String ConnString
    {
        get
        {
            //HDS ConnectionString comes from the Web.Config
            return ConfigurationManager.ConnectionStrings["Chart RelayConnectionString"].ConnectionString;

        }
    }

    private String ProviderSearch
    {
        get
            {
                 String srchCmd = "Select PHYSICIAN_NPI, LAST_NAME, FIRST_NAME, ADDRESS_1, CITY, STATE, PHONE from Provider";

                 string whereClause = string.Empty;

                 if (txtSearchCity.Text.Length > 0)
                    whereClause = " WHERE CITY = @SearchCity";
                 if (txtSearchState.Text.Length > 0)
                      {
                         if (whereClause.Length > 0)
                              whereClause += " AND ";

                         else
                             whereClause = " WHERE ";
                             whereClause += "STATE = @SearchState";
                      }
                 if (txtSearchZip.Text != "")
                      {
                         if (whereClause.Length > 0)
                             whereClause += " AND ";

                         else
                             whereClause = " WHERE ";
                             whereClause += "ZIP = @SearchZip";
                      }
                      return srchCmd + whereClause + " ORDER BY WEIGHT";
            }
    }



    protected SqlDataAdapter CreateProviderInsAdapter()
    {
        SqlConnection connProvIns = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(SearchProviderIns, connProvIns);


        if (txtSearchInsur.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchInsur", txtSearchInsur.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchInsur", string.Empty));

        SqlDataAdapter sqlDAphyins = new SqlDataAdapter(cmd);
        sqlDAphyins.FillSchema(HDSDataSet, SchemaType.Mapped, "PHYSINS");
        sqlDAphyins.Fill(HDSDataSet, "PHYSINS");-------------------------<<<<<<<<<<<<<<<<<<<<-------------ERROR Occurs Here
        return sqlDAphyins;
    }

    protected SqlDataAdapter CreateProviderSpecialAdapter()
    {
        SqlConnection connPhysSpecial = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(SearchProvSpecialty, connPhysSpecial);

        if
            (txtSearchSpecial.Text != "")
             cmd.Parameters.Add(new SqlParameter("@SearchSpecialty", txtSearchSpecial.Text));
         else
             cmd.Parameters.Add(new SqlParameter("@SearchSpecialty", string.Empty));

        SqlDataAdapter sqlDAphyspecial = new SqlDataAdapter(cmd);
        sqlDAphyspecial.FillSchema(HDSDataSet, SchemaType.Mapped, "PHYS_SPECIALTIES");
        sqlDAphyspecial.Fill(HDSDataSet, "PHYS_SPECIALTIES");

        return sqlDAphyspecial;
    }


0
Comment
Question by:kwh3856
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20323636
as you do this:
>                 if (txtSearchCity.Text.Length > 0)
>                    whereClause = " WHERE CITY = @SearchCity";

you don't need the "else" part in here:

  if (txtSearchCity.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchCity", txtSearchCity.Text));
//        else
//            cmd.Parameters.Add(new SqlParameter("@SearchCity", string.Empty));
               


0
 

Author Comment

by:kwh3856
ID: 20323683
I commented those lines and still get the error message.  Is there something else I am missing?

Thanks
Kenny
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 2000 total points
ID: 20323716
perhaps

declare your cmd as cmd1

SqlCommand cmd1 = new SqlCommand(SearchProviderIns, connProvIns);
SqlDataAdapter sqlDAphyins = new SqlDataAdapter(cmd1);

as you have a cmd variable declared once
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:vbturbo
ID: 20323744
though it should be a new instance of the command object and also should outside scope of the first declaration
but according the err msg it looks like it use's the first cmd object in the second fill

vbturbo
0
 
LVL 11

Expert Comment

by:DotNetThinker
ID: 20323928
Have you tried clearing the DataSet before each Fill?
0
 
LVL 6

Expert Comment

by:townsma
ID: 20324862
I may be going blind in my old age, but there is no definition shown above for the "SearchProviderIns", can you please show this.  I suggect this is probably needing a parameter called @SearchCity, but you are not providing it.  
0
 

Author Comment

by:kwh3856
ID: 20325253
Here is all the code.  I did not realize it was not pasted in.

Thanks
Kenny






--------------------------------------------------------------------------------------------------------------------------------------

private DataSet mDataSet = null;
    public DataSet HDSDataSet
    {
        get
        {
            if (mDataSet == null)
                mDataSet = new DataSet("HDSDataSet");
            return mDataSet;
        }
    }


   

    protected void PopulateProviderTable()
    {

       
        SqlDataAdapter sqlDA = CreateProviderAdapter();
        SqlDataAdapter sqlDAphyins = CreateProviderInsAdapter();
        SqlDataAdapter sqlDAphyspecial = CreateProviderSpecialAdapter();
        SqlDataAdapter sqlDAphyspecialproc = CreateProviderSpecialProcAdapter();
       
       
        errormessage.Text = ProviderSearch;
        errormessage2.Text = SearchProviderIns;
        errormessage3.Text = SearchProvSpecialty;

       // Create Relations - Setup Key Fields
        DataColumn doctorId = HDSDataSet.Tables["PROVIDER"].Columns["PHYSICIAN_NPI"];
        DataColumn insurId = HDSDataSet.Tables["PHYSINS"].Columns["PHYSICIAN_NPI"];
        DataColumn specialtiesId = HDSDataSet.Tables["PHYS_SPECIALTIES"].Columns["PHYSICIAN_NPI"];

        // Create Relations - Build Relation
        DataRelation specialtiesRelation = new DataRelation("specialtiesRelation", doctorId, specialtiesId);
        DataRelation insurRelation = new DataRelation("insurRelation", doctorId, insurId);
        HDSDataSet.Relations.Clear();
        HDSDataSet.Relations.Add(insurRelation);
        HDSDataSet.Relations.Add(specialtiesRelation);
 
       
    }


    protected SqlDataAdapter CreateProviderAdapter()
    {
        SqlConnection conn = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(ProviderSearch, conn);

        if
            (txtSearchCity.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchCity", txtSearchCity.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchCity", string.Empty));
               
        if
            (txtSearchState.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchState", txtSearchState.Text));
   //     else
    //        cmd.Parameters.Add(new SqlParameter("@SearchState", string.Empty));

        if (txtSearchZip.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchZip", txtSearchZip.Text));
   //     else
     //       cmd.Parameters.Add(new SqlParameter("@SearchZip", string.Empty));

       
        SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
       
        sqlDA.FillSchema(HDSDataSet, SchemaType.Mapped, "PROVIDER");
        sqlDA.Fill(HDSDataSet, "PROVIDER");

        return sqlDA;
    }

    private String ConnString
    {
        get
        {
            //HDS ConnectionString comes from the Web.Config
            return ConfigurationManager.ConnectionStrings["Chart RelayConnectionString"].ConnectionString;

        }
    }

    private String ProviderSearch
    {
        get
            {
                 String srchCmd = "Select PHYSICIAN_NPI, LAST_NAME, FIRST_NAME, ADDRESS_1, CITY, STATE, PHONE from Provider";

                 string whereClause = string.Empty;

                 if (txtSearchCity.Text.Length > 0)
                    whereClause = " WHERE CITY = @SearchCity";
                 if (txtSearchState.Text.Length > 0)
                      {
                         if (whereClause.Length > 0)
                              whereClause += " AND ";

                         else
                             whereClause = " WHERE ";
                             whereClause += "STATE = @SearchState";
                      }
                 if (txtSearchZip.Text != "")
                      {
                         if (whereClause.Length > 0)
                             whereClause += " AND ";

                         else
                             whereClause = " WHERE ";
                             whereClause += "ZIP = @SearchZip";
                      }
                      return srchCmd + whereClause + " ORDER BY WEIGHT";
            }
    }



    protected SqlDataAdapter CreateProviderInsAdapter()
    {
        SqlConnection connProvIns = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(SearchProviderIns, connProvIns);


        if (txtSearchInsur.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchInsur", txtSearchInsur.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchInsur", string.Empty));

        SqlDataAdapter sqlDAphyins = new SqlDataAdapter(cmd);
        sqlDAphyins.FillSchema(HDSDataSet, SchemaType.Mapped, "PHYSINS");
        sqlDAphyins.Fill(HDSDataSet, "PHYSINS");
        return sqlDAphyins;
    }

    protected SqlDataAdapter CreateProviderSpecialAdapter()
    {
        SqlConnection connPhysSpecial = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(SearchProvSpecialty, connPhysSpecial);

        if
            (txtSearchSpecial.Text != "")
             cmd.Parameters.Add(new SqlParameter("@SearchSpecialty", txtSearchSpecial.Text));
         else
             cmd.Parameters.Add(new SqlParameter("@SearchSpecialty", string.Empty));

        SqlDataAdapter sqlDAphyspecial = new SqlDataAdapter(cmd);
        sqlDAphyspecial.FillSchema(HDSDataSet, SchemaType.Mapped, "PHYS_SPECIALTIES");
        sqlDAphyspecial.Fill(HDSDataSet, "PHYS_SPECIALTIES");

        return sqlDAphyspecial;
    }

    protected SqlDataAdapter CreateProviderSpecialProcAdapter()
    {
        SqlConnection connPhysSpecialProc = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand(SearchProvSpecialtyProc, connPhysSpecialProc);

        if
            (txtSearchSpecialProcCode.Text != "")
            cmd.Parameters.Add(new SqlParameter("@SearchSpecialtyProc", txtSearchSpecialProcCode.Text));
        else
            cmd.Parameters.Add(new SqlParameter("@SearchSpecialtyProc", string.Empty));

        SqlDataAdapter sqlDAphyspecialproc = new SqlDataAdapter(cmd);
        sqlDAphyspecialproc.FillSchema(HDSDataSet, SchemaType.Mapped, "SPECIAL_PROCEDURES");
        sqlDAphyspecialproc.Fill(HDSDataSet, "SPECIAL_PROCEDURES");
        return sqlDAphyspecialproc;
    }


   

   

    private String SearchProviderIns
    {
        get
        {
            // String srchCmd = "Select * from PHYSINS";
            String srchCmd = "Select * from PHYSINS where INSURANCE_CARRIER_NAME = @SearchInsur AND PHYSICIAN_NPI in(SELECT PHYSICIAN_NPI FROM Provider)";
            srchCmd += ProviderSearch;

            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;

        }
    }
0
 

Author Closing Comment

by:kwh3856
ID: 31410236
After I reconfigured it properly I got it to work with your idea.  Thanks
0
 
LVL 11

Expert Comment

by:DotNetThinker
ID: 20327964
Is it working for you now?
0
 

Author Comment

by:kwh3856
ID: 20328357
DotNetThinker,
Yes, it is working now but I have another problem with the search not returning the expected results.  Please look at my post to see if you have any ideas.

Thanks
Kenny
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

864 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