Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
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
Updated 17-Jan-13 19:06pm
v2

1 solution

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

C#
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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900