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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:11:36+00:00 2026-05-22T22:11:36+00:00

I am writing some code that will prepare my database for my application. In

  • 0

I am writing some code that will prepare my database for my application. In the code there are some repetitive SQL statements when I am creating a table, and I want to hide them in some methods (there are only two for now: creating the primary key and making the id of the table an auto-increment one in postgres). For the simple case of the primary key, I first wrote a function like this:

public void MakePrimaryKey(DbConnection conn, string tblName, string colName)
{
    conn.Execute(@"
ALTER TABLE ""@tblName""
    ADD CONSTRAINT ""@constrName"" PRIMARY KEY(""@colName"")
    ", new { tblName = tblName,
             constrName = tblName + "_pkey",
             colName = colName } );
}

After much fiddling around with errors and exceptions, I finally concluded that using parameters in this fashion is not really supported, so I switched to a traditional string.Format() call, and all was well.

But I am not really satisfied. Is this way of using parameters really not supported? If so, what are the places that I can safely use these parameters? Only for the variable parts of the SQL query – such as the places where I can use a stored procedure parameters?

  • 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-22T22:11:36+00:00Added an answer on May 22, 2026 at 10:11 pm

    If I remember correctly, Dapper uses a parameterized IDbCommand to execute its queries.

    Parameterized queries are simply string replacement operations.

    To be more specific, a parameterized query lets you have parameters in your query, sends the values for those parameters, and then SQL Server handles compiling the queries and passing the values for the parameters.

    If you can’t create a parameterized query with plain ADO.NET using the desired syntax, Dapper.NET isn’t going to be able to do it for you either.

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

Sidebar

Related Questions

I am writing some new code that will throw a custom exception - I
I'm writing some documentation that will occasionally include C# or C++ code snippets. In
I am writing a macro for Visual studio that will generate some code. I
I'm writing some code that will need to speak to a web service over
I'm writing some C++ code that will have to send data over TCP/IP. I
I need help with writing some code that will create a random number from
I'm writing some code that will get executed before the DOM loads, basically, using
I am writing a calendar-based web application and am working on some code that
I am writing code that will use AJAX requests to get some HTML code
I'm writing some code that id like to be able to work with any

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.