i am developing a web application in c#,i want to write sql query by using string.format function as follows:
string sSql = string.Format("Select * From {0}", DbReference.TABLE_NAME_SEC_ROLES);
if (roleCriteria._roleName != null && roleCriteria._isEnabled == true)
sSql += string.Format(" where {0}={1} and {2}={3} " + DbReference.ROLE_NAME_COL, roleCriteria._roleName, DbReference.IS_ENABLED_COL, roleCriteria._isEnabled);
if (roleCriteria._roleName != null)
sSql += string.Format(" where {1} = {2} " + DbReference.ROLE_NAME_COL, roleCriteria._roleName);
if (roleCriteria._isEnabled == true)
sSql += string.Format("where {0}" + DbReference.IS_ENABLED_COL + "'false'");
and it gives me exception as follows:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
so, Please give me solution on this exception.
String.Formatyou should useParameters.