I have the following code
public DataSet GetProject(string projectID)
{
DataSet dataTable = new DataSet();
DataAccess dataAccess = new DataAccess();
OracleCommand commandOb = new OracleCommand();
strQuery.Append("select projectName, managerName");
strQuery.Append("from project ");
strQuery.Append("where projectID = '" + projectID + "'");
cmd.CommandText = strQuery.ToString();
dataTable = dataAccess.ExecuteDataAdapter(commandOb);
return dataTable;
}
Is this an okay way to build a query and execute it? Would this be vulunerable to SQL injection attacks?
Is there a recommended approach when it comes to building queries dynamically. Any help would be appreciated.
Stay away from Dynamic querystry using Parameterized Query's instead and if you are not familiar with how to do that.. then usestring.Format(Select projectName,managerName from project where ProjectID={0}", projectID);+1StoredProcedure can't go wrong with that either