Showing posts with label box. Show all posts
Showing posts with label box. Show all posts

Thursday, March 22, 2012

( ) problem

hi all,

i have some problem in my web application, am using vb.net

i have a text box and an add button, when the user click on the add button, whatever written in the textbox stores on my sql database

the problem is whenever there is a ( ' ) character in the text, it send me error

i know why this problem occure but i dont know what is the reqired code for it

this is the code:

sql.commandtext = "INSERT INTO myDB (Ques) VALUES ('" & txtQues.text & "')

what is the solution?

The answer is very simple in C# those are literals and in ANSI SQL they are Delimited Identifiers per ANSI SQL 92 and SQL Server is compliant so try the link below on how to enable it and handle it correctly. Hope this helps.

http://msdn2.microsoft.com/en-us/library/ms176027.aspx

|||

If you think about it, you are putting together the string before it gets sent to SQL Server. So, if your value has a single quote it, your insert would look something like:

INSERT INTO myDB (Ques) VALUES ('myvalue's')

This is confusing. The string seems to end after the 'e', when you really want it to end after the 's'. As said, SQL Server is taking that literally. If you're going to build the insert statement this way (as opposed to using a stored procedure), you need to replace single quotes with two single quotes (not a double quote - literally two single quotes).

txtQues.Text.Replace("'", "''")

The string passed to the database will be:

INSERT INTO myDB (Ques) VALUES ('myvalue''s')

which the database will interpret correctly.

|||Parameterized queries.|||thanks alot... for your helpBig Smile

Thursday, February 16, 2012

<<SQL2k5>>

Can I have SQL2k5, Sql2k2, Sql2k5 Express Edition installed and functioning
correctly on 1 box?
TIA> Can I have SQL2k5, Sql2k2, Sql2k5 Express Edition installed and
functioning
> correctly on 1 box?
From
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/sseoverview.asp:
Multiple SQL Server 2005 Express installations can coexist on the same
machine along with other installations of SQL Server 2000, SQL Server 2005,
or Microsoft Desktop Engine (MSDE). In general, it is best that SQL Server
2000 instances be upgraded to SP3a or higher. The maximum limit to the
number of SQL instances is 50 on the same machine. These instances must be
uniquely named for the purpose of identifying them.
Still, be aware that SQL 2005 is in Beta version, so you might experience
problems. I prefer installing beta versions in a virtual machine.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com