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

  • Home
  • SEARCH
  • 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 865255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:36:45+00:00 2026-05-15T09:36:45+00:00

I have the following struct in C# class public struct Employee { public const

  • 0

I have the following struct in C# class

public struct Employee
        {
            public const string EMPID = "EMP_ID";
            public const string FName = "FIRST_NAME";
            public const string LNAME = "LAST_NAME";
            public const string DEPTID = "DEPT_ID";

        }

Is there an easy way to build a string as follows

const string mainquery="INSERT INTO EMP(EMP_ID,FIRST_NAME,LAST_NAME,DEPT_ID) VALUES(:EMP_ID,:FIRST_NAME,:LAST_NAME,:DEPT_ID)"

Instead of doing as follows
and then concatenating it.

const string EMP_COLS=
                EMPLOYEE.EMPID + "," +
                EMPLOYEE.FNAME + "," +
        EMPLOYEE.LNAME + "," +
                EMPLOYEE.DEPTID;

            const string EMP_Values=
                EMPLOYEE.EMPID + ":" +
                EMPLOYEE.FNAME + ":" +
        EMPLOYEE.LNAME + ":" +
                EMPLOYEE.DEPTID;
  • 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-15T09:36:46+00:00Added an answer on May 15, 2026 at 9:36 am

    You could try something like this:

    StringBuilder sb = new StringBuilder();
    var fields = typeof(Employee).GetFields();
    for (int i = 0; i < fields.Length; ++i)
    {
        sb.Append(fields[i].GetValue(new Employee()));
        if (i < fields.Length - 1)
        {
            sb.Append(',');
        }
    }
    
    string result = sb.ToString();
    // The above will be "EMP_ID,FIRST_NAME,LAST_NAME,DEPT_ID"
    

    Edit: Note that above I’m assuming you’ve got using directives for both System.Reflection and System.Text.

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

Sidebar

Related Questions

I have the following code: #include <map> #include <string> class policy1 { public: struct
I have the following struct: public struct Declarations { public const string SchemaVersion =
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I have the following: namespace Test { public class Location { public string city
I have the following code: class outer { struct inner { int var1; int
We have a class whose semantic behaviour is like the following :- struct Sample
I have the following code: class Foo<T> where T : struct { private T
I have the following struct private struct sData{ public int volume; public System.Timers.Timer aliveTimer;
Suppose I have the following: struct Person { std::string mName; Birthday mBirthday; }; using
Say, I have the following struct in C# : public struct MyStructCSharp { private

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.