Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one table column name are username and email insert table

asp.net web application using suppose any one giving this type of input throw run time error how to solve

user name : len'
email : lenin@gmail.com

user name using (') throw error

what can i do

What I have tried:

i give validation only getting characters only but i need more idea about this problem
Posted
Updated 23-Jan-18 2:36am
Comments
Karthik_Mahalingam 23-Jan-18 6:44am    
post the code what you have tried.
Use Improve question to edit the question.
F-ES Sitecore 23-Jan-18 6:48am    
I don't understand the question but I'm assuming you are using string concatenation to make your sql

string sql = "insert into table values ('" + Textbox1.Text + "')"

The answer is to use parameterised queries (google "ado.net parameterised queries"), and also give your text boxes proper names.
Laxmidhar tatwa technologies 23-Jan-18 9:40am    
sir u have to mandatory to pass all the values i this type of query

Hi,
this happen because of '(single quot).
you need to know about SQL injection Preventing SQL Injection Attacks[^]
and parameterized queries Using Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]

I hope this will solve your problem.
 
Share this answer
 
Quote:
what can i do

Post asp code.
This error smells like an "sql injection" problem.

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
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