473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HtmlEncoding, SQL Encoding in ASP.NET

Hey,

What are the usual ways to encode a sql string for safe insertion into the
db? Are there
handy functions like php's addslashes, etc? or should i use the Regexp, or
string.Replace functions?

Cheers
Chris
Nov 18 '05 #1
3 1526
It depends on the db. Generally, you can simply replace single quotes with
doubled single quotes to escape them.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Chris" <ch***@no-spam.tuxweb.org> wrote in message
news:10*************@corp.supernews.com...
Hey,

What are the usual ways to encode a sql string for safe insertion into the
db? Are there
handy functions like php's addslashes, etc? or should i use the Regexp, or
string.Replace functions?

Cheers
Chris

Nov 18 '05 #2
Hi Chris,

You probably should be using SQLParameters which takes care of all encoding
as well as pretty much doing away with Sql Injection problems.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Chris" <ch***@no-spam.tuxweb.org> wrote in message
news:10*************@corp.supernews.com...
Hey,

What are the usual ways to encode a sql string for safe insertion into the
db? Are there
handy functions like php's addslashes, etc? or should i use the Regexp, or
string.Replace functions?

Cheers
Chris

Nov 18 '05 #3
Chris wrote:
What are the usual ways to encode a sql string for safe insertion into the
db? Are there
handy functions like php's addslashes, etc? or should i use the Regexp, or
string.Replace functions?


Chris, use a parameterized query, like:

string SQL = "SELECT * FROM TableName WHERE Foo = @Bar";

Note the @Bar is a parameter. Then, you can set a value for the
parameter by adding a SqlParameter or OleDbParameter instance to the
Command object's Parameters collection.

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Christopher H. Laco | last post by:
Long story longer. I need to get web user input into a backend system that a) only grocks single byte encoding, b) expectes the data transer to be 1 bytes = 1 character, and c) uses the HP Roman-6...
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
4
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml...
6
by: Martin Smith | last post by:
How can I stop ASP.NET Encoding things automatically? e.g if I create a button in my code and add the following attribute objNewButton.Attributes.Add("onClick",...
8
by: Tim_Mac | last post by:
hi, i have a group of individual radio buttons that i am running some client-side code on for the onClick event. there is a URL generated by a code block inside the onClick attribute. the...
0
by: Chris McDonough | last post by:
ElementTree's XML serialization routine implied by tree._write(file, node, encoding, namespaces looks like this (elided): def _write(self, file, node, encoding, namespaces): # write XML to file...
4
by: Christina | last post by:
Hey Guys, Currently, I am using the below code: Dim oReqDoc as XmlDocument Dim requiredBytes As Byte() requiredBytes = System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.InnerXml). Here, I am...
3
by: mortb | last post by:
1. How do I determine which encoding a xmldocument or xmlreader uses when opening a document? I'm not just talking about the <?xml encoding="utf-8"?attribute, but the actual encoding of the...
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.