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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:38:15+00:00 2026-06-18T08:38:15+00:00

I am inserting values into a database but i get an error when the

  • 0

I am inserting values into a database but i get an error when the value to be inserted has an apostrophe e.g Jo’s. How do i resolve this?
This is my code

     SqlDataReader readerReference = cmd_Reference.ExecuteReader();

        int loginIndex = readerReference.GetOrdinal("a column");
        int DomCodeLoginIndex = readerReference.GetOrdinal("a column");
        int dom_domain = readerReference.GetOrdinal("dom_domaine"); 
        int emp_surname = readerReference.GetOrdinal("a column");
        int emp_name = readerReference.GetOrdinal("a column");
        int srv_name = readerReference.GetOrdinal("a column");
        int emp_model_tel = readerReference.GetOrdinal("a column");
        int emp_EntryDate = readerReference.GetOrdinal("a column");
        int emp_Telephone = readerReference.GetOrdinal("a column");
        int emp_Mobile = readerReference.GetOrdinal("a column");
        int emp_Email = readerReference.GetOrdinal("a column");


        string insert = "INSERT INTO EMP_tracking(emp_login, emp_dom_code, emp_domain,   emp_affectation_date, emp_surname" +
            ",emp_name, emp_service,emp_telephone_model" +
            ",emp_entry_date" +
            ",emp_telephone_number" +
            ",emp_cellphone_number" +
            ",emp_email) VALUES ('{0}',{1},'{2}','"+DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") +"','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')";




    string toInsert = string.Format(insert, readerReference.GetString(loginIndex),
                                            readerReference.GetInt32(DomCodeLoginIndex ), 
                                            readerReference.GetString(dom_domain),
                                            readerReference.GetString(emp_surname ),
                                            readerReference.GetString(emp_name), 
                                            readerReference.GetString(srv_name), 
                                            readerReference.GetString(emp_model_tel), 
                                            readerReference.GetDateTime(emp_EntryDate), 
                                            readerReference.GetString(emp_Telephone),
                                            readerReference.GetString(emp_Mobile), 
                                            readerReference.GetString(emp_Email)
                                   );      


    cmd_Insert.CommandText = toInsert;
    cmd_Insert.ExecuteNonQuery();

Let’s say the column concerned is emp_login. How will the solution be implemented on it?

  • 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-18T08:38:16+00:00Added an answer on June 18, 2026 at 8:38 am

    This question comes up over and over again. You should not create SQL strings using concatenation – instead use paremeters:

    string insert = "INSERT INTO EMP_tracking(emp_login, emp_dom_code, emp_domain,   emp_affectation_date, emp_surname" +
            ",emp_name, emp_service,emp_telephone_model" +
            ",emp_entry_date" +
            ",emp_telephone_number" +
            ",emp_cellphone_number" +
            ",emp_email) VALUES (@emp_login, @emp_dom_code, //... etc.";
    
    cmd_Insert.Parameters.AddWithValue("@emp_login", readerReference.GetString(loginIndex));
    cmd_Insert.Parameters.AddWithValue("@emp_dom_code", readerReference.GetInt32(DomCodeLoginIndex));
    //etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I'm inserting some HTML into a MySQL database table. But when I get it
I'm experiencing a problem inserting values into a SQLite database. The data I download
Hi I'm inserting Latitude, Longitude values into the database. INSERT INTO `Tracks` (`Latitude`, `Longitude`,
i have a problem in inserting the listbox value into mysql database in vb
i have a problem in inserting the listbox value into mysql database in vb
I am inserting a date into my database, the value which comes from: s.theDate
I am inserting values into a table and below is my code protected void
I have a non-nullable database column which has a default value set. When inserting

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.