public static List <dynamic> ExecuteParseAll(this SqlCommandScope command, List <TypeHandler> typeHandlerList = null) { #region Contracts if (command == null) { throw new ArgumentException(); } #endregion // TypeHandler SqlMapper.ResetTypeHandlers(); foreach (var typeHandler in typeHandlerList) { SqlMapper.AddTypeHandler(typeHandler.Type, typeHandler); } // Execute using (SqlDataReader reader = command.ExecuteReader()) { // Parse var resultList = reader.Parse(); if (resultList == null) { throw new InvalidOperationException("resultList=null"); } // Return return(resultList.ToList()); } }
public static dynamic ExecuteParse(this SqlCommandScope command, List <TypeHandler> typeHandlerList = null) { #region Contracts if (command == null) { throw new ArgumentException(); } #endregion // Return return(command.ExecuteParseAll(typeHandlerList).FirstOrDefault()); }
// Methods private void InsertData() { // Select using (var command = new SqlCommandScope(_connectionString)) { // CommandParameters command.Parameters.Add(new SqlParameter("@Id", Guid.NewGuid().ToString())); command.Parameters.Add(new SqlParameter("@Name", Guid.NewGuid().ToString())); // CommandText command.CommandText = @"INSERT INTO Users (Id, Name) VALUES (@Id, @Name)"; // Execute command.ExecuteNonQuery(); } }
private void RefreshData() { // Result DataTable dataTable = new DataTable(); // Select using (var command = new SqlCommandScope(_connectionString)) { // CommandText command.CommandText = @"SELECT Id, Name FROM Users"; // Create using (SqlDataReader reader = command.ExecuteReader()) { dataTable.Load(reader); } } // Display this.DisplayGridView.DataSource = dataTable; }