Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How in VB.net we can encode string for SQL

For example, in sql

all ` should be replaced with `` right?

Well, is there a function built in by vb.net that does that sort of thing already?

That way I do not have to encode it.

By the way, I do not access sql database directly. Basically I am creating a text file and that text file contains raw sql statements. Most of the answers deal with accessing sql data directly.

like image 399
Anonymous White Avatar asked Aug 31 '26 23:08

Anonymous White


1 Answers

I don't think so as I think the only case where something like this would be relevant is if you were doing inline SQL Commands without parameters.

This has a risk of SQL Injection, and therefore you should create commands like this:

Dim cmd As New SqlCommand("UPDATE [TableA] SET ColumnA=@ColumnA WHERE ID=@ID", Conn)
cmd.Parameters.Add("@ColumnA", SqlDbType.NVarChar).Value = txtColumnA.Text
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID
cmd.ExecuteNonQuery()
like image 127
Curtis Avatar answered Sep 03 '26 15:09

Curtis