Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can System.Data.DataRow used for SQL injection?

I am aware that for SqlCommand I have to use SqlParameter when passing parameters to the query, to avoid SQL injection. But what about the DataRow? For example:

row.UserComment = tbUserComment.Text;

Here "row" is a System.Data.DataRow that will be saved to the DB with an SqlDataAdapter. And "tbUserComment.Text" is an ASP.NET TextBox that is filled by the user.
Can this be used for SQL injection? If yes, then what can I do to prevent it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

See in this documentation: https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqldataadapter?view=dotnet-plat-ext-6.0

The InsertCommand, DeleteCommand, and UpdateCommand are generic templates that are automatically filled with individual values from every modified row through the parameters mechanism.

So this will automatically parameterize the DataRow meaning there should be no possibility of SQL injection if this pattern is adhered to.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading