Jump to content
php.lv forumi

Kā pareizāk/labāk papildināt query ar Where + and + ... +


Sasa

Recommended Posts

Sveiki,

 

Kā ir labāk pareizāk papildināt sql query ar papildu parametriem sākuma tas ir parasts query, kurš papildināt ar WHERE + AND + AND atkarībā kas ir izvēlēts meņu utt.

 

Man šobrīd ir tā ka ir izveidots

string = "";

kurā ierakstās WHERE nosacījums atkarībā no tā, kas ir iekš URL parametriem atrodams.

Link to comment
Share on other sites

apmēram kaut kā šādi:

 

QueryString qs = new QueryString();
           string sqlAadditional = string.Empty;
           Utils validate = new Utils();
           if (validate.isValid(qs, connectionString, "raz"))
           {
               usedFilters.Visible = true;
               if (string.IsNullOrEmpty(sqlAadditional))
               {
                   sqlAadditional += "WHERE razotajs.IDrazotajs = " + qs.GetParameter("raz");
               }
               else
               {
                   sqlAadditional += " AND razotajs.IDrazotajs = " + qs.GetParameter("raz");
               }
}

 

Un lieku klāt jau kādam sql'am:

Razotajs razotajsDataTable = new Razotajs();
           string sqlManufacturer =
               "SELECT DISTINCT razotajs.IDrazotajs, razotajs.nosaukums FROM materialaparametrs Inner Join razotajs ON materialaparametrs.IDrazotajs = razotajs.IDrazotajs Inner Join materials ON materials.IDmaterials = materialaparametrs.IDmaterials Inner Join materialakategorija ON materialakategorija.IDmaterialaKategorija = materials.IDmaterialaKategorija " + sqlAadditional;
           DataTable razotaji = razotajsDataTable.getRazotajsFromDB(connectionString, sqlManufacturer);
           foreach (DataRow manufacturer in razotaji.Rows)
           {
               if (!validate.isValid(qs, connectionString, "raz"))
               {
                   prepereManufacturerFilter(manufacturer);
               }
           }

Edited by Sasa
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...