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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:20:48+00:00 2026-06-14T18:20:48+00:00

I am trying to use PostgreSQL with C# (not asp.net) via Npqsql , I

  • 0

I am trying to use PostgreSQL with C# (not asp.net) via Npqsql, I created a table with the name GenData with SQL;

CREATE TABLE gendata
(
  empname text NOT NULL,
  pyrll text NOT NULL,
  contracno text,
  expird date,
  dtbrth date,
  plbrth text,
  cid text,
  passport text,
  jndt date,
  postn text,
  dept text,
  hmtwn text,
  familymen numeric,
  contno text,
  CONSTRAINT gendata_pkey PRIMARY KEY (pyrll)
)

I tried to insert to the table with the following code:

String sql = String.Format("INSERT INTO GenData VALUES ({0},{1},{2},'{3}',{4},{5},{6},{7},{8},{9},{10},{11},{12},{13});"
                    ,textBox1.Text
                    ,textBox2.Text
                    ,textBox3.Text
                    ,textBox4.Text
                    ,textBox5.Text
                    ,textBox6.Text
                    ,textBox7.Text
                    ,textBox8.Text
                    ,textBox9.Text
                    ,textBox10.Text
                    ,textBox11.Text
                    ,textBox12.Text
                    ,textBox13.Text
                    ,textBox14.Text);

But I always get an exception like:
enter image description here

  • 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-14T18:20:49+00:00Added an answer on June 14, 2026 at 6:20 pm

    Since you are not using SQL Parameters, but directly embed values into the string (which is considered quite bad practice), you should follow SQL syntax. In your particular situation, you should wrap all string parameters into '.

    Better way is to use SQLParameter class to allow .NET perform all necessary transformations on input data, escape the data to avoid sql-injections and so on. I’m not quite familiar with Npgsql, but I’m almost sure it follows the same guidelines as the other .NET database providers, so you should be able to use the SQLParameter class the same way.

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

Sidebar

Related Questions

I'm trying to use a SQL Array type with PostgreSQL 8.4 and the JDBC4
I'm trying to create new aggregate function in PostgreSQL to use instead of the
I'm trying to use heroku db:push to upload my local postgresql database to the
I am trying to use Heroku and apparently Postgresql is a lot more strict
I am trying to use a double primary key as a foreign key. Create
I am trying to use PostgreSQL's currval function to return the last inserted row
I'm trying to use a function with PostgreSQL to save some data. Here is
I'm trying to use libpq, the client library for PostgreSQL in a Cocoa app.
Trying to recreate my SQL Server database on PostgreSQL. Everything is ok except I
I am trying to create a simple stored procedure in PostgreSQL within which I

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.