Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 989331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:46:33+00:00 2026-05-16T05:46:33+00:00

hello Friends please verify my code Is it a right way to pass optional

  • 0

hello Friends please verify my code
Is it a right way to pass optional parameter to a method.
if any thing wrong please suggest me if there exist any better solution.

protected void Ok_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int course_id = Convert.ToInt32(course.SelectedValue);
                int passoutYear = Convert.ToInt32(passout.SelectedValue);
                int currentBacklog = Convert.ToInt32(currrentBacklogDDL.SelectedValue);
                int sex = Convert.ToInt32(gender.SelectedValue);
                int? eGap = null;
                int? firstYrPercent = null;
                int? secondYrPercent = null;
                int? thirdYrPercent = null;
                int? finalYearpercent = null;
                int? currentDegeePercentage = null;
                int? highSchoolPercentge = null;
                int? higherSchoolPercentage = null;
                int? grauationPercentage = null;
                int? diplomaPercentage = null;
                int? noOfAtkt = null;

                string dateOfBirth = DOB.Text.Trim();
                DateTime birthDate = DateTime.ParseExact(dateOfBirth, "dd/mm/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                string outPut = birthDate.ToString("mm/dd/YYYY");
                DateTime date = Convert.ToDateTime(outPut);

                if (!String.IsNullOrEmpty(educationGap.Text))
                {
                    eGap = Convert.ToInt32(educationGap.Text.Trim());
                }
                if (!string.IsNullOrEmpty(firstYear.Text))
                {
                    firstYrPercent = Convert.ToInt32(firstYear.Text.Trim());
                }
                if (!string.IsNullOrEmpty(secondYear.Text))
                {
                    secondYrPercent = Convert.ToInt32(secondYear.Text.Trim());
                }
                if (!string.IsNullOrEmpty(thirdYear.Text))
                {
                    thirdYrPercent = Convert.ToInt32(thirdYear.Text.Trim());
                }
                if (!string.IsNullOrEmpty(finalyear.Text))
                {
                    finalYearpercent = Convert.ToInt32(finalyear.Text.Trim());
                }
                if (!string.IsNullOrEmpty(currentDegree.Text))
                {
                    currentDegeePercentage = Convert.ToInt32(currentDegree);
                }
                if (!string.IsNullOrEmpty(higherSchool.Text.Trim()))
                {
                    higherSchoolPercentage = Convert.ToInt32(higherSchool.Text.Trim());
                }
                if (!string.IsNullOrEmpty(highSchool.Text))
                {
                    highSchoolPercentge = Convert.ToInt32(highSchool.Text.Trim());
                }
                if (!string.IsNullOrEmpty(graduation.Text))
                {
                    grauationPercentage = Convert.ToInt32(graduation.Text.Trim());
                }
                if (!string.IsNullOrEmpty(diploma.Text))
                {
                    diplomaPercentage = Convert.ToInt32(diploma.Text.Trim());
                }
                if (!string.IsNullOrEmpty(atkt.Text))
                {
                    noOfAtkt = Convert.ToInt32(atkt.Text.Trim());
                }

                Dictionary<string, object> paramList = new Dictionary<string, object>();
                paramList.Add("@courseId", course_id);
                paramList.Add("@passoutYear", passoutYear);
                paramList.Add("@currentBacklog", currentBacklog);
                paramList.Add("@sex", sex);
                paramList.Add("@eGap", eGap);
                paramList.Add("@firstYrPercent", firstYrPercent);
                paramList.Add("@secondYrPercent", secondYrPercent);
                paramList.Add("@thirdYrPercent", thirdYrPercent);
                paramList.Add("@finalYearpercent", finalYearpercent);
                paramList.Add("@currentDegeePercentage", currentDegeePercentage);
                paramList.Add("@highSchoolPercentge", highSchoolPercentge);
                paramList.Add("@higherSchoolPercentage", higherSchoolPercentage);
                paramList.Add("@grauationPercentage", grauationPercentage);
                paramList.Add("@diplomaPercentage", diplomaPercentage);
                paramList.Add("@noOfAtkt", noOfAtkt);

                StringBuilder branchId= new StringBuilder();
                foreach (ListItem li in branch.Items)
                {
                    if (li.Selected)
                    {
                        branchId.Append(Convert.ToInt32(li.Value));
                    }
                }
                DataTable dt = searchManager.GetEligibleStudent(paramList, branchId);



            }

        }
        catch (Exception ex) 
        {
            COMMON.logger.Error("Error On Button click Ok", ex);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:46:34+00:00Added an answer on May 16, 2026 at 5:46 am

    it’s a bit sad that you first convert the values to the correct value, then put it into a list of object such that in GetEligibleStudent, you’ll have to cast those values again.

    My guess would be to create a class for this, such that, say, higherSchoolPercentage becomes a field. Since you’ll be getting student records back, it might even be that you can reuse this structure.

    hth,
    Nic

    UPDATE

    create a class like

    class StudentQuery
    {
        public int course_id;
        ...
        public int? egap = null;
        ...   
    
    }
    

    then, in your page, say

    StudentQuery sq = new StudentQuery();
    
    if (!String.IsNullOrEmpty(educationGap.Text))
    {
        sq.eGap = Convert.ToInt32(educationGap.Text.Trim());
    }
    

    Then you can say

    DataTable dt = searchManager.GetEligibleStudent(sq, branchId);
    

    Like this,

    • you keep the type of the variables
    • you don’t have to create this paramList
    • the separation between problem structure (which fields you got) and data (which values the fields have) is clearer.

    UPDATE 2

    Since the only format in which these fields are required is, in fact, the key/value list that’s built here, to be passed on to an SQL command, I think the code sample is ok. One might still think about refactoring that code into a separate method, but my previous suggestion of creating a class turns out to be, in fact, superfluous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends i am to add optional parameter to pass these in a method
Hello friends I have tried many times but I am not successful than please
hello friends i m new to jQuery and nyro modal. right now i m
Hello friends i am running code given below which contains the setLogTimeEntery function and
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
Hello Friends check my code http://jsfiddle.net/sUaky/2/ i want to load a web page in
Hello friends I am new to TableView.....I want help..please I have to set the
Hello Friends I am using the following code to show the amount entered in
hello friends i have tryied folowing code as u can see here http://jsfiddle.net/QCdz4/ i
Hello friends following is my code HTML <ul class=menu-item> <li>item</li> <li>item</li> <li>item</li> </ul> CSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.