Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with adding SQL paramerters from data access Layer in c#
    primarykey
    data
    text
    <p>First I am giving examples of two methods</p> <pre><code>public static List&lt;FormGridEntity&gt; GetAllCandidatesByProgram(string programShortName) { List&lt;FormGridEntity&gt; formGridEntities = null; try { string cmd = SELECT + " WHERE " + CANDIDATE_PROGRAM_PA + " = " + CANDIDATE_PROGRAM;`enter code here` //string cmd = SELECT DAOParameters dps = new DAOParameters(); dps.AddParameter(CANDIDATE_PROGRAM_PA, programShortName); List&lt;SqlParameter&gt; ps = Common.Methods.GetSQLParameters(dps); SqlDataReader dataReader = QueryHandler.ExecuteSelectQuery(cmd, ps); formGridEntities = Maps(dataReader); dataReader.Close(); } catch (Exception exception) { throw exception; } return formGridEntities; } </code></pre> <p>and another method is </p> <pre><code>public static List&lt;FormGridEntity&gt; GetAllCandidatesByDates(DateTime initialDate,DateTime finalDate) { List&lt;FormGridEntity&gt; formGridEntities = null; try { string cmd = SELECT + " WHERE " + FORM_SUBMISSION_DATE_PA + " BETWEEN " + initialDate + " AND " + finalDate; //string cmd = SELECT DAOParameters dps = new DAOParameters(); //What will I do here? since **//dps.AddParameter(FORM_SUBMISSION_DATE_PA, initialDate); //dps.AddParameter(FORM_SUBMISSION_DATE_PA, finalDate);** List&lt;SqlParameter&gt; ps = Common.Methods.GetSQLParameters(dps); SqlDataReader dataReader = QueryHandler.ExecuteSelectQuery(cmd, ps); formGridEntities = Maps(dataReader); dataReader.Close(); } catch (Exception exception) { throw exception; } return formGridEntities; } </code></pre> <p>I have commentd out</p> <p>Here the caps terms are all constants that above in the class like</p> <pre><code>private const string FORM_PURCHASING_DATE = "DateOfPurchase"; private const string FORM_PURCHASING_DATE_PA = "@DateOfPurchase" private const string FORM_SUBMISSION_DATE = "DateOfSubmission"; private const string FORM_SUBMISSION_DATE_PA = "@DateOfSubmission"; </code></pre> <p>the SELECT is also defined correctly. I am using this Layer perfectly. But now a scenario ocurred where I am getting confused what to do. So far I have been adding values with parameter that has one to one relationship. But, in my second method, I am using the between operator where two values is referring to one parameter, what will I write here to make the things working properly. I have commented out the particular region that I want to modify. please help me if possible. Here is the method GetSQLParameters public static List GetSQLParameters(DAOParameters dps) { List parameters = new List();</p> <pre><code> foreach (DictionaryEntry de in dps.hs) { SqlParameter p = new SqlParameter(); p.ParameterName = de.Key.ToString(); if (de.Value.ToString() == Convert.ToString(0)) { p.Value = DBNull.Value; } else { p.Value = de.Value; } parameters.Add(p); } return parameters; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload