all groups > vb.net data > july 2007 >
You're in the

vb.net data

group:

validate SQL-query


Re: validate SQL-query William (Bill) Vaughn
7/12/2007 10:09:09 AM
vb.net data:
Again, it's the job of the provider's (MySQL's data access interface) to
handle all single quote issues--if you use it. Instead of passing raw SQL to
the engine, pass a parameterized query. The provider is responsible for
framing the strings properly.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

[quoted text, click to view]

validate SQL-query Erik van Engelen
7/12/2007 6:28:10 PM
Is it possible to validate or format a dynamic SQL-query in vb.net?

I have an application that passes data from a form to a MySQL database.
This data can include all kinds of user passed data like single quotes
or reserved words. Before creating the query i want to format the data
with a function.

I've worked with vb6 for 6 years but .net is new to me.

Re: validate SQL-query Phil
7/13/2007 12:00:00 AM
[quoted text, click to view]

I'm new to .NET too. I think what Bill is saying is:
instead of using:

sql = "UPDATE table SET field='" & TextBox.Text & "'"
cmd.ExecuteNonQuery(sql)

you should use something like :

sql = "UPDATE table SET field=@Field"
cmd.Parameters.Add("@Field", OleDBType.VarChar).Value=TextBox.Text
cmd.ExecuteNonQuery(sql)

Is that right?

Re: validate SQL-query William (Bill) Vaughn
7/13/2007 11:25:33 AM
Right. ;)

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
[quoted text, click to view]
Re: validate SQL-query Jack Jackson
7/30/2007 8:03:06 AM
On Mon, 30 Jul 2007 16:06:39 +0200, Erik van Engelen
[quoted text, click to view]

Depending on which provider you are using, you may need to use '?'
Re: validate SQL-query Erik van Engelen
7/30/2007 4:06:39 PM
[quoted text, click to view]

Sadly this doesn't work. I have the following code:

Dim dbParam As Data.Common.DbParameter
Command_DBt = Dbt.CreateCommand 'Dbt is the target mysql-ODBC connection)

strSQLCommand = "INSERT INTO afwijking (`afwijkid`, `grstid`, `dgrpid`,
`afwijking`) VALUES (@field0,@field1,@field2,@field3);"

Command_DBt.CommandText = strSQLCommand
Do While Reader_DBs.Read
For tel_fields = 0 To maxcount_fields - 1

dbParam = Command_DBt.CreateParameter
dbParam.DbType = DbType.Int64
dbParam.ParameterName = "@field" & tel_fields.ToString
dbParam.Value = Reader_DBs.GetValue(tel_fields)
Command_DBDoel.Parameters.Add(dbParam)
Next (tel_fields)

Command_DBDoel.ExecuteNonQuery()
Command_DBDoel.Parameters.Clear()
Loop

This is probably not to most efficient code but it should work. When i
look in the mysql query logs i get "INSERT INTO afwijking
(`afwijkid`,`grstid`,`dgrpid`,`afwijking`) VALUES
(@field0,@field1,@field2,@field3)". This means the parameters are not
replaced by the values. The MS-help is not very helpful in giving
examples or explanations. I've been googling for a day now but i can't
seem to find the problem.

Re: validate SQL-query William (Bill) Vaughn
8/27/2007 11:28:55 AM
Jack is 100% right. OLE DB generally does not support named parameters
except for recent SQL Server providers--you'll have to use the appropriate
parameter markers like "?" or ":" (for Oracle).

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
[quoted text, click to view]
Re: validate SQL-query Phil
8/29/2007 12:00:00 AM

[quoted text, click to view]

I've been using named parameters with Access/Jet & OleDb with no problems.
I've not tried it with Oracle though.

AddThis Social Bookmark Button