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 7046541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:39:46+00:00 2026-05-28T02:39:46+00:00

I have a class with the following method. public cIPLink(int paramCaseNo, int paramIPID, string

  • 0

I have a class with the following method.

public cIPLink(int paramCaseNo, int paramIPID, string paramIPReference, int paramContactID)
    {            
        this.cLinkDate = DateTime.Now;
        this.cCaseNo = paramCaseNo;
        this.cIPID = paramIPID;
        this.cIPReference = paramIPReference;
        this.cContactID = paramContactID;

        string strConnect = BuildConnectionString();
        SqlConnection linkToDB = new SqlConnection(strConnect);
        linkToDB.Open();

        string sqlStat = "INSERT INTO tblIPLinks (LinkID, LinkDate, CaseNo, IPID, ContactID, IPReference)" +
                         "VALUES (@LinkID, @LinkDate, @CaseNo, @IPID, @ContactID, @IPReference);";
        SqlCommand sqlCom = new SqlCommand(sqlStat, linkToDB);

        sqlCom.Parameters.Add("@LinkID", SqlDbType.Int);
        sqlCom.Parameters.Add("@LinkDate", SqlDbType.Date);
        sqlCom.Parameters.Add("@CaseNo", SqlDbType.Int);
        sqlCom.Parameters.Add("@IPID", SqlDbType.Int);
        sqlCom.Parameters.Add("@ContactID", SqlDbType.Int);
        sqlCom.Parameters.Add("@IPReference", SqlDbType.Text);

        this.cLinkID = NextLinkID();

        sqlCom.Parameters["@LinkID"].Value = this.cLinkID;
        sqlCom.Parameters["@LinkDate"].Value = this.cLinkDate;
        sqlCom.Parameters["@CaseNo"].Value = this.cCaseNo;
        sqlCom.Parameters["@IPID"].Value = this.cIPID;
        sqlCom.Parameters["@ContactID"].Value = this.cContactID;
        sqlCom.Parameters["@IPReference"].Value = this.cIPReference;

        sqlCom.ExecuteNonQuery();

        linkToDB.Close();
    }

However I want to make this a little more flexible. Sometimes when the method is called I want to drop the field IPID, and sometimes I want to drop the field ContactID. Now I thought about copying and pasting this code and having three overload methods; one with just IPID, one wth just ContactID and a third with both fields, but I’m sure there must be a neater way of doing what I want.

Any ideas?

  • 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-28T02:39:47+00:00Added an answer on May 28, 2026 at 2:39 am

    If you are using dotnet 4.0 and above, you can use optional parameters.

    public cIPLink(int paramCaseNo, int paramIPID = -1, 
        string paramIPReference = null, int paramContactID = -1)
    

    So, from that moment on you can invoke it as follows:

    cIPLink( paramCaseNo );
    cIPLink( paramCaseNo, paramContactID:5 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class: public abstract class AbstractParent { static String method() {
I have a UserBll class which has following method public string GetaspnetUserIdByUserName(string name )
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have the following method: public static string UlList(this HtmlHelper helper, List<IEntity> entities, string
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following extension method public static class ListExtensions { public static IEnumerable<T>
I have following class with one static method: public class Helper { public static
I have a static utility class, FileUtils which has the following method: public static
I have a class MyClass with a method: public bool MyMethod(out DateTime? MyDate) {

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.