Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
whenever i use a word with apostrophe like it's , it generate's " a error in mysql command check your manual ".
because as we use '"& texbox.text &"' in mysql commmand . so as we type something like this it input as 'its's' and generate error , so any solution . Waiting ........
 
for Better Understanding.
 
Dim cn As New MySqlConnection
    Dim cd As MySqlCommand
    Dim s As String
 
cn.ConnectionString = "server=localhost; user id=root; password=; database=dc"
            cn.Open()
s = " insert into table_name(column1,column2,..column_n) values('"& textbox1.text&"')"
            cd = New MySqlCommand(s, cn)
            cd.ExecuteNonQuery()
            cn.Close()
Posted 17-Jan-13 0:20am
Edited 17-Jan-13 19:06pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Can you provide a code that causes this error. You have mentioned using tag that asp.net 4 is used. It is really hard to achieve such behavior using framework.
 
Generally speaking, it is recommended to use prepared statements to execute the query.
For example, if SQLCommand is used - the code could be
 
command->CommandText = S"insert into Region (RegionID, RegionDescription) values (@id, @desc)" ;
command->Parameters->Add (S"@id", __box(id));
command->Parameters->Add (S"@desc", desc);
command->Prepare();  // Calling Prepare after having set the CommandText and parameters.
command->ExecuteNonQuery();
 

 
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.prepare(v=vs.71).aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 335
1 Gihan Liyanage 332
2 OriginalGriff 236
3 ClimerChinna 222
4 vikinghunter 168
0 Sergey Alexandrovich Kryukov 8,243
1 OriginalGriff 7,109
2 CPallini 2,598
3 Richard MacCutchan 1,980
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100