Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. RichTextbox

RichTextbox

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasehelp
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Socheat Net
    wrote on last edited by
    #1

    I have forum page in my web site, i want user to type comments and can insert icon also like richtextbo, but i don'w know, one thing i have problem with symbal such as single quote i can not insert in to database by using ASP.NET:zzz: ................

    P S 3 Replies Last reply
    0
    • S Socheat Net

      I have forum page in my web site, i want user to type comments and can insert icon also like richtextbo, but i don'w know, one thing i have problem with symbal such as single quote i can not insert in to database by using ASP.NET:zzz: ................

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      Use a properly parameterised query and you should be fine.

      S M 2 Replies Last reply
      0
      • P Paddy Boyd

        Use a properly parameterised query and you should be fine.

        S Offline
        S Offline
        Socheat Net
        wrote on last edited by
        #3

        I don't know how to use it ................

        P 1 Reply Last reply
        0
        • S Socheat Net

          I don't know how to use it ................

          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          Can i point you towards google?

          //Start connection and create command object etc.

          string mySql;

          mySql = "Insert into myTable (aField) values (@MyValue)"

          sqlCommand.CommandType = CommandType.Text;
          sqlCommand.CommandText = mySql;
          sqlCommand.Parameters.Add(new SqlParameter("@MyValue", theActualValue));

          //Execute your command

          This is roughly the syntax.

          S 1 Reply Last reply
          0
          • P Paddy Boyd

            Can i point you towards google?

            //Start connection and create command object etc.

            string mySql;

            mySql = "Insert into myTable (aField) values (@MyValue)"

            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.CommandText = mySql;
            sqlCommand.Parameters.Add(new SqlParameter("@MyValue", theActualValue));

            //Execute your command

            This is roughly the syntax.

            S Offline
            S Offline
            Socheat Net
            wrote on last edited by
            #5

            It is possible if i use it in Microsoft Access? ................

            1 Reply Last reply
            0
            • S Socheat Net

              I have forum page in my web site, i want user to type comments and can insert icon also like richtextbo, but i don'w know, one thing i have problem with symbal such as single quote i can not insert in to database by using ASP.NET:zzz: ................

              P Offline
              P Offline
              Paddy Boyd
              wrote on last edited by
              #6

              My isn't google[^] wonderful.

              1 Reply Last reply
              0
              • P Paddy Boyd

                Use a properly parameterised query and you should be fine.

                M Offline
                M Offline
                Mihai Drebot
                wrote on last edited by
                #7

                There is an esier fix for this specific problem, although it's not highly recomended: use a [your_string].Replace("'","''"); This fixes the ' ruining your sql sintax. Just make sure you read a bit about sql injection threat. You realy should try and use strong typed, prametrized stored procedures. Mihai Voicu Drebot, .Net developer

                S 1 Reply Last reply
                0
                • S Socheat Net

                  I have forum page in my web site, i want user to type comments and can insert icon also like richtextbo, but i don'w know, one thing i have problem with symbal such as single quote i can not insert in to database by using ASP.NET:zzz: ................

                  S Offline
                  S Offline
                  Sushant Duggal
                  wrote on last edited by
                  #8

                  Hi, you can either replace single quote with two single quotes or use HttpUtility.HtmlEncode("YOUR TEXT") before inserting it to database... and use HttpUtility.HtmlDecode("DB CONTENTS") before displaying it. I hope it helps you Thanks Sushant Duggal.

                  S 1 Reply Last reply
                  0
                  • S Sushant Duggal

                    Hi, you can either replace single quote with two single quotes or use HttpUtility.HtmlEncode("YOUR TEXT") before inserting it to database... and use HttpUtility.HtmlDecode("DB CONTENTS") before displaying it. I hope it helps you Thanks Sushant Duggal.

                    S Offline
                    S Offline
                    Socheat Net
                    wrote on last edited by
                    #9

                    Can give an example? ................

                    S 1 Reply Last reply
                    0
                    • M Mihai Drebot

                      There is an esier fix for this specific problem, although it's not highly recomended: use a [your_string].Replace("'","''"); This fixes the ' ruining your sql sintax. Just make sure you read a bit about sql injection threat. You realy should try and use strong typed, prametrized stored procedures. Mihai Voicu Drebot, .Net developer

                      S Offline
                      S Offline
                      Socheat Net
                      wrote on last edited by
                      #10

                      Can u give me sql statement? ................

                      M 1 Reply Last reply
                      0
                      • S Socheat Net

                        Can give an example? ................

                        S Offline
                        S Offline
                        Sushant Duggal
                        wrote on last edited by
                        #11

                        suppose your freetextbox ID is txtContents so what we do is : string sqlQuery = "insert into tablename(contents) values('" + HttpUtility.HtmlEncode(txtContents.Text) + "')"; now use this query to insert the record. When you try to display this data .... suppose you get data back from database in dataset. and column name is Content string returnedContents = HttpUtility.HtmlDecode(ds.tables[0].rows[0]["Content"].ToString()); Now you can display it in the page. I am typing directly here, so please check typo mistakes. Thanks Sushant Duggal.

                        1 Reply Last reply
                        0
                        • S Socheat Net

                          Can u give me sql statement? ................

                          M Offline
                          M Offline
                          Mihai Drebot
                          wrote on last edited by
                          #12

                          say you have to store a string , myString, in a table named demoTable, in the info field you would simply have this sql: @"insert into demoTable (info) values ('"+myString+"')" before you do that, you have to do this: myString = myString.Replace("'","''"); this way, you have 2 ' instead of one, and that's interpreted by the sql as a single quote inside a string value, rather than a single quote terminating the string value. Again, make sure you read about the sql injection attacks

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups