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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:59:45+00:00 2026-05-25T12:59:45+00:00

I have an enum as below: [Flags] public enum AggregationLevel { /// <summary> ///

  • 0

I have an enum as below:

[Flags]
public enum AggregationLevel
{
    /// <summary>
    /// 00000001
    /// </summary>
    Department = 1,

    /// <summary>
    /// 00000010
    /// </summary>
    Gbu = 2,

    /// <summary>
    /// 00000100
    /// </summary>
    Division = 4,

    /// <summary>
    /// 00001000
    /// </summary>
    Region = 8,

    /// <summary>
    /// 00010000
    /// </summary>
    Market = 16,

    /// <summary>
    /// 00100000
    /// </summary>
    Cluster = 32,

    /// <summary>
    /// 01000000
    /// </summary>
    Store = 64
}

Then I have a stored procedure parameter which requires a varbinary (array of bytes).

I have an enum instance which should be passed to it:

AggregationLevel thisLevel = AggregationLevel.Department & AggregationLevel.Division;

Then, the value should be passed to this stored procedure:

var parameter = new SqlParameter("@pBitMask", SqlDbType.VarBinary)

parameter = ?

How to convert my ‘thisLevel’ enum to an array of bytes so that it can be assigned to this sql parameter?

Thanks,

  • 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-25T12:59:45+00:00Added an answer on May 25, 2026 at 12:59 pm

    A few things..

    1) You need to use OR rather than AND:

    AggregationLevel thisLevel = AggregrationLevel.Department | AggregationLevel.Division;
    

    2) You can use this sequence so you don’t have to remember powers of 2 in decimal:

    0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100 ...
    

    3) Finally, varbinary is not what you want. Look at integer or bigint. Enums are stored as ints or longs, and you are limited to the number of bits in an int or a long. If you do want to store in a varbinary, you’ll need to serialise a value to a string of bytes, will will vary depending on whether you want big-endian, how many bytes should be used for storage – maybe it’s even variable, etc. More information needed.

    Two options for #3:

    A. If it’s just you/code under your control, don’t use varbinary, use int or bigint (depending on number of bits required). Better still (potentially), use bit fields instead, if you’re going to query on them

    B. If it’s not, the DBA or app provider will be able to specify how they want their varbinary populated

    Hope that helps.

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

Sidebar

Related Questions

I have a flag enum below. [Flags] public enum FlagTest { None = 0x0,
I have enum like this [Flags] public enum Key { None = 0, A
i have enum public enum TypeImage { Img=0, Thumb=1 } i want in view
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have an enum that looks as follows: public enum TransactionStatus { Open =
I have an enum construct like this: public enum EnumDisplayStatus { None = 1,
I have an Enum called Status defined as such: public enum Status { VALID(valid),
I have a Enum for example... public enum TypeIdentifier { NotSet = 0, Type1=
I have an enum public enum FileExtentions { mp3, mpeg } And I have
I have a situation where I need the Checker enum below used in multiple

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.