Click here to Skip to main content
16,004,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
May superior told that it will solve my issue but i want to know how it works. So can anyone elaborate it.?


VB
Dim dt As New DataTable
        Dim da As New SqlDataAdapter("select max(sl_no) from e1 where project.project_id and e1.project_id = '" + Project_IDTextBox.Text + "'", con)
Posted

1 solution

It creates two new objects (which it does nothing to tie together).
One is a DataTable which under normal conditions contains the data from a data source such as an SQL database, but in this case contains nothing.
The other is a DataAdapter which would normally be used to supply the data to a DataTable or similar object. In this case, the adapter is prepared with a SQL connection, and a (bad) select statement to restrict the record returned.

And your superior is an idiot. Using code like that opens your database up to an SQL Injection attack which can accidentally or deliberately damage or destroy your database. Google "Bobby Tables" and don't assume that what you find is just a joke. Use parametrised queries instead of concatenating strings.
 
Share this answer
 
Comments
armarzook 1-Nov-12 4:34am    
u have any alternate code to do this same thing so that accident can never happen?
OriginalGriff 1-Nov-12 4:55am    
As I said - use parametrised queries.
A quick google with give you loads of info on how and why.
fjdiewornncalwe 1-Nov-12 14:22pm    
+5. If for nothing else then the "And your superior..." statement.

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