public void Insert(DRPenv values) { try { string[] DRPValues = values.ToArray(); using SqlConnection connection = new SqlConnection(builder.ConnectionString); connection.Open(); //sql string builder @VALUE is used for SQL injection prevention string sql = "INSERT INTO env VALUES ("; for (int i = 0; i < DRPValues.Length - 1; i++) { if (i == DRPValues.Length - 2) { sql += "@VALUE" + i.ToString() + ")"; } else { sql += "@VALUE" + i.ToString() + ","; } } using SqlCommand command = new SqlCommand(sql, connection); for (int i = 0; i < DRPValues.Length - 1; i++) { command.Parameters.AddWithValue("@VALUE" + i.ToString(), DRPValues[i]); } command.ExecuteReader(); } catch (SqlException) { /*sad react if this happens*/ } }
public bool CheckNull(DRPenv env) { string[] array = env.ToArray(); for (int i = 0; i < array.Length - 1; i++) { if (string.IsNullOrEmpty(array[i])) { return(true); } } return(false); }