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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:13:53+00:00 2026-06-18T15:13:53+00:00

Hello everyone i am creating a settings page for another application using mvc4. In

  • 0

Hello everyone i am creating a settings page for another application using mvc4. In the settings page:

1.It contains two text areas wherein the user can type anything.

2.After typing if the user clicks submit button, the text he has written is saved in a sql database.

3.The main application will read that data from the database and display it.

Here are my respective codes:

Model:

 public string PartnerInfo1 { get; set; }
 public string PartnerInfo2 { get; set; }

Controller:

[HttpPost]
        public ActionResult Index(AddDetailModel model)
        {
            pinfo1 = model.PartnerInfo1;
            pinfo2 = model.PartnerInfo2;
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sample"].ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("update dbo.Partner_Design set PartnerInfo1='" + pinfo1 + "',PartnerInfo2='" + pinfo2 + "' where [PartnerID]='cs'", con);
            cmd.ExecuteNonQuery();
            return RedirectToAction("Index");
        }

and in the view:

 @Html.TextAreaFor(m => m.PartnerInfo1)
@Html.TextAreaFor(m => m.PartnerInfo2)

in the database, the corresponding table contains two columns PartnerInfo1,PartnerInfo2 and their datatype is nvarchar(max).

My problem is when i type apostrophe in text area it gives me error.For example if i type “world’s” it gives error on clicking submit button.

This is the error:

Incorrect syntax near 's'.
Unclosed quotation mark after the character string ''.

Please suggest what i can do to avoid this.Any help would be appreciated.

  • 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-18T15:13:54+00:00Added an answer on June 18, 2026 at 3:13 pm

    Your method expose your query to sql injection attacks. You are much better using a parameterised query which will sort out your ' issue as well.

    string connString = ConfigurationManager.ConnectionStrings["Sample"].ConnectionString;
    
    using (SqlConnection con = new SqlConnection(connString))
    {
       SqlCommand cmd = new SqlCommand("Update dbo.Partner_Design " +
                                        "Set PartnerInfo1=@pinfo1, " +
                                            "PartnerInfo2=@pinfo2 " +
                                        "Where [PartnerID]=@partnerId", con);
    
       cmd.Parameters.AddWithValue("@pinfo1", model.PartnerInfo1);
       cmd.Parameters.AddWithValue("@pinfo2", model.PartnerInfo2);
       cmd.Parameters.AddWithValue("@partnerId", "cs");
       con.Open();
       cmd.ExecuteNonQuery();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone i am creating a login page using mvc4 wherein the login credentials
Hello Everyone I've created a jsp page in which I created two drop down
Hello everyone i am designing a web page that contains many textboxes and a
Hello everyone i need some help. I'm trying to make an application for mac
hello everyone i have a problem with my 3-tiers application i don't know how
Hello everyone I'm trying to remove some characters in my text box For example
hello everyone i struggling to pass two parameter to an event handler basically when
Hello everyone here... I need to build up a swing application related to vehicle
Hello everyone i have a problem I have a text $text = some and
Hello everyone how can I get two values from different select boxes? I get

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.