how to insert a name Ram's in Sql Server database

Posted by Mrutyunjay51 under Sql Server on 5/18/2011 | Points: 10 | Views : 1992 | Status : [Member] | Replies : 8
how can i want to insert a name like Ram's in sql server database.




Responses

Posted by: SheoNarayan on: 5/18/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Before passing the value into SQL statement replace single quote with two single quote. like ' with '' and it will work.

However I would suggest to use the parameterized SQL statement rather than passing direct value into the SQL statement.

Look at this post where it has been demonstrated - http://www.itfunda.com/how-to-insert-records-into-the-database/Free/126

Using parameterized SQL Statement helps you to avoid SQL Injection as well.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tijut2k on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down
you make a function:

function string stringQuoReplace(string txt) {

Replace(txt,"'", "''")
}


and on ur sql statmnt, would look something like this:
text = stringSwap(text);

string SQL = "INSERT INTO tabel (First, Second, Third) VALUES (number, text, text)"

what that code does, is to replace ' with '' <-- 2 single quotes, not double quotes.



Best Regard's
Tiju Thankachan

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/19/2011 [Member] Bronze | Points: 25

Up
0
Down
try this....
insert into employee values ('c03','Ram''s')   //not a double quote. two single quotes


Thanks,


Nitha Deepak

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 12/8/2011 [Member] Silver | Points: 25

Up
0
Down
Replace the single quote with Apostrophe
function string stringQuoReplace(string txt) {

Replace(txt,"'","`")

}

Thanks,
Sanjay

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
INSERT INTO CTEST VALUES('RAM''S')


REGARDS



sriram

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
CREATE TABLE Sample
( NAME VARCHAR(50) )

INSERT INTO Sample VALUES ('RAM')


Try this..


Ajay
ajaypatelfromsanthal.blogspot.in

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/7/2012 [Member] Starter | Points: 25

Up
0
Down
Repalce single quote with two single quote

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/8/2012 [Member] Silver | Points: 25

Up
0
Down
Yes,JUst like SheoNarayan said please replace single quote with two single quote.It will works

@SheoNarayan
Nice Explanation.

Mrutyunjay51, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response