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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:35:54+00:00 2026-06-04T07:35:54+00:00

I have an entity Report whose values I want to insert into a database

  • 0

I have an entity Report whose values I want to insert into a database table. The following attributes of Report have to be inserted:

reportID - int
RoleID - int
Created_BY = SYSTEM(default)
CURRENT_TIMESTAMP

Now the problem is with the 2nd attribute. I have a report with the LIST<ROLES> attributes. ROLES is a well defined entity which has an ID and a NAME. From this list I have to extract every role and insert each role’s ID into the table.

So my query presently looks as below :

INSERT INTO REPORT_MARJORIE_ROLE(REPORT_ID, ROLE_ID, CREATED_BY, CREATED)
VALUES({0}, {1}, 'SYSTEM', CURRENT_TIMESTAMP)

The C# code from where I am parsing these values is as follows :

try
{
    StringBuilder _objSQL = new StringBuilder();
    _objSQL.AppendFormat(Queries.Report.ReportQueries.ADD_NEW_ROLES, report.ID, "report.MarjorieRoles.Add(MarjorieRole")); 
    _objDBWriteConnection.ExecuteQuery(_objSQL.ToString());
    _objDBWriteConnection.Commit();
    _IsRolesAdded = true;
}

So please guide me how to add roles from C# function

  • 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-06-04T07:35:56+00:00Added an answer on June 4, 2026 at 7:35 am

    I’m assuming you say SQL (structured query language) and you really mean Microsoft SQL Server (the actual database product) instead – right?

    You cannot insert a whole list as a whole into SQL Server – you need to insert one row for each entry. This means, you need to call the INSERT statement multiple times.

    Do it like this:

    // define the INSERT statement using **PARAMETERS**
    string insertStmt = "INSERT INTO dbo.REPORT_MARJORIE_ROLE(REPORT_ID, ROLE_ID, CREATED_BY, CREATED) " + 
                        "VALUES(@ReportID, @RoleID, 'SYSTEM', CURRENT_TIMESTAMP)";
    
    // set up connection and command objects in ADO.NET
    using(SqlConnection conn = new SqlConnection(-your-connection-string-here))
    using(SqlCommand cmd = new SqlCommand(insertStmt, conn)
    {
        // define parameters - ReportID is the same for each execution, so set value here
        cmd.Parameters.Add("@ReportID", SqlDbType.Int).Value = YourReportID;
        cmd.Parameters.Add("@RoleID", SqlDbType.Int);
    
        conn.Open();
    
        // iterate over all RoleID's and execute the INSERT statement for each of them
        foreach(int roleID in ListOfRoleIDs)
        {
          cmd.Parameters["@RoleID"].Value = roleID;
          cmd.ExecuteNonQuery();
        }
    
        conn.Close();
    }      
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entity (getters and setters ommited)... @Entity @Table(name = TBL_PROJECT_RUN) public
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have two entity classes annotated in the following way @Entity class A {
I have this DB design: CREATE TABLE report ( ID MEDIUMINT PRIMARY KEY NOT
I have a method that contains the following Linq to SQL code: public List<L2SBusinessEntities.Report.MesReport>
I have a custom entity in a relational database that I have mapped to
A Report can have multiple charts. The Chart table looks as follows: Chart --
I have a database table which records all field changes in all database tables
Background: We have large flat files span around 60GB and are inserting into database.
Let's say we have: @Entity public class Order { @Id private int id; @OneToMany(mappedBy=order)

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.