I am fairly new to SQL but have been using it throughout my application for a while now. The way I am executing statements does not seem to be the most viable option since it can present issues for the likes of SQL injections etc.
This is an example of a chunk of code in my application which demonstrates how I am currently using SQL.
//Select all active devices.
string ActiveUsers = "SELECT * FROM Devices WHERE Status='" + "Online" + "'";
SqlCommand cmd = new SqlCommand(ActiveUsers, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
con.Close();
Would you please be able to advice me on how to modify this code so that its more secure and reserves less risks?
Many thanks.