static void DisconnectedDataLayer(SqlConnection connection, SqlDataAdapter dataAdapter, string queryString) { var ddl = new DisconnectedDataLayer(connection, dataAdapter); string tableName = "Departments"; var data = ddl.QueryData(queryString, tableName); #region Adding Row to Table var table = data.Tables[tableName]; var newRow = table.NewRow(); newRow["Name"] = "Operations"; newRow["GroupName"] = "IT"; newRow["ModifiedDate"] = DateTime.Now; table.Rows.Add(newRow); #endregion try { ddl.InsertData(data, tableName); data = ddl.QueryData(queryString, tableName); } catch (Exception ex) { Console.WriteLine(ex.Message); } #region Getting Row to Delete var rowsToDelete = data.Tables[tableName] .AsEnumerable() .Where(r => r.Field <string>("GroupName") == "IT") .ToList(); #endregion var deletedData = ddl.DeleteData(data, rowsToDelete, tableName); }
static void DisconnectedDataLayerWithParameters(SqlConnection connection, SqlDataAdapter dataAdapter, string paramQueryString) { var tableName = "Persons"; var ddl = new DisconnectedDataLayer(connection, dataAdapter); var param = new SqlParameter() { ParameterName = "@LastNameLike", Value = "Hernan" }; var personData = ddl.QueryData(paramQueryString, param, tableName); foreach (DataRow row in personData.Tables[tableName].AsEnumerable()) { Console.WriteLine($"{row.Field<string>("FirstName")} {row.Field<string>("LastName")}"); } }