public static void AddRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { try { //add new row AutoLotDataSet.InventoryRow newRow = table.NewInventoryRow(); Console.WriteLine("Enter new color:"); newRow.Color = (string)Console.ReadLine(); Console.WriteLine("Enter new Make:"); newRow.Make = (string)Console.ReadLine(); Console.WriteLine("Enter new PetName:"); newRow.PetName = (string)Console.ReadLine(); table.AddInventoryRow(newRow); ////another way (Dont forget about position in constructor) //Console.WriteLine("Enter new color:"); //string strColor = (string)Console.ReadLine(); //Console.WriteLine("Enter new Make:"); //string strMake = (string)Console.ReadLine(); //Console.WriteLine("Enter new PetName:"); //string strPetName = (string)Console.ReadLine(); //table.AddInventoryRow(strMake, strColor, strPetName); adapter.Update(table); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void AddRecords( AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { try { // Get a new strongly typed row from the table. AutoLotDataSet.InventoryRow newRow = table.NewInventoryRow(); // Fill row with some sample data. newRow.Color = "Purple"; newRow.Make = "BMW"; newRow.Name = "Saku"; // Insert the new row. table.AddInventoryRow(newRow); // Add one more row, using overloaded Add method. table.AddInventoryRow("Yugo", "Green", "Zippy"); // Update database. adapter.Update(table); } catch (Exception ex) { WriteLine(ex.Message); } }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable tb, InventoryTableAdapter dAdapt) { AutoLotDataSet.InventoryRow rowToDelete = tb.FindByCarID(999); dAdapt.Delete(rowToDelete.CarID, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); rowToDelete = tb.FindByCarID(888); dAdapt.Delete(rowToDelete.CarID, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Strongly Typed DataSets *****\n"); AutoLotDataSet.InventoryDataTable table = new AutoLotDataSet.InventoryDataTable(); InventoryTableAdapter dAdapt = new InventoryTableAdapter(); dAdapt.Fill(table); // Add rows, update, and reprint. AddRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); PrintInventory(table); Console.ReadLine(); RemoveRecords(table, dAdapt); dAdapt.Fill(table); PrintInventory(table); Console.ReadLine(); CallStoredProc(); Console.ReadLine(); }
static void Main(string[] args) { WriteLine("***** Fun with Strongly Typed DataSets *****\n"); // Caller creates the DataSet object. var table = new AutoLotDataSet.InventoryDataTable(); // Inform adapter of the Select command text and connection. var adapter = new InventoryTableAdapter(); // Fill our DataSet with a new table, named Inventory. adapter.Fill(table); PrintInventory(table); WriteLine(); // Add rows, update and reprint. AddRecords(table, adapter); table.Clear(); adapter.Fill(table); PrintInventory(table); WriteLine(); // Remove rows we just made and reprint. RemoveRecords(table, adapter); table.Clear(); adapter.Fill(table); PrintInventory(table); WriteLine(); CallStoredProc(); ReadLine(); }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) // Удаление записей { AutoLotDataSet.InventoryRow toDeleteRow = table.FindByCarID(999); adapter.Delete(toDeleteRow.CarID, toDeleteRow.Make, toDeleteRow.Color, toDeleteRow.PetName); toDeleteRow = table.FindByCarID(888); adapter.Delete(toDeleteRow.CarID, toDeleteRow.Make, toDeleteRow.Color, toDeleteRow.PetName); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Strongly Typed DataSets *****\n"); // Caller creates the DataSet object. AutoLotDataSet.InventoryDataTable table = new AutoLotDataSet.InventoryDataTable(); // Inform adapter of the Select command text and connection. InventoryTableAdapter dAdapt = new InventoryTableAdapter(); // Fill our DataSet with a new table, named Inventory. dAdapt.Fill(table); PrintInventory(table); Console.WriteLine(); // Add rows, update and reprint. AddRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); PrintInventory(table); Console.WriteLine(); // Remove rows we just made and reprint. RemoveRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); PrintInventory(table); Console.WriteLine(); CallStoredProc(); Console.ReadLine(); }
// 用生成的代码插入数据 public static void AddRecords(AutoLotDataSet.InventoryDataTable tb, InventoryTableAdapter dAdapt) { try { // 从表中获取新的强类型的行 AutoLotDataSet.InventoryRow newRow = tb.NewInventoryRow(); // 使用一些示例数据填充该行 newRow.CarID = 999; newRow.Color = "Purple"; newRow.Make = "BMW"; newRow.PetName = "Saku"; // 插入新行 tb.AddInventoryRow(newRow); // 使用重载的Add方法添加另一个行 tb.AddInventoryRow(888, "Yugo", "Green", "Zippy"); // 更新数据库 dAdapt.Update(tb); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void PrintInventory(AutoLotDataSet.InventoryDataTable table) { //Print out the column names foreach (var tableColumn in table.Columns) { Write(tableColumn + "\t"); } WriteLine("\n-------------------------------"); //print the datatable foreach (DataRow item in table.Rows) { Write($"{item["Carid"].ToString()}\t"); Write($"{item["Make"].ToString()}\t"); Write($"{item["Color"].ToString()}\t"); Write($"{item["PetName"].ToString()}\t"); WriteLine(); } //use either or //for (int curRow = 0; curRow < table.Rows.Count; curRow++) //{ // for (int curCol = 0; curCol < table.Columns.Count; curCol++) // { // Write($"{table.Rows[curRow][curCol] }\t"); // } // WriteLine(); //} }
static void Main(string[] args) { Console.WriteLine("***** Fun with Strongly Typed DataSets *****\n"); AutoLotDataSet.InventoryDataTable table = new AutoLotDataSet.InventoryDataTable(); InventoryTableAdapter dAdapt = new InventoryTableAdapter(); dAdapt.Fill(table); PrintInventory(table); // Добавить строки, обновить и вывести повторно AddRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); PrintInventory(table); // Удалить строки, обновить и вывести повторно RemoveRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); PrintInventory(table); CallStoredProc(); Console.ReadLine(); }
private static void AddRecords(AutoLotDataSet.InventoryDataTable dt, InventoryTableAdapter dAdapt) { try { // Получить из таблицы новую строго типизированную строку AutoLotDataSet.InventoryRow newRow = dt.NewInventoryRow(); // Заполнить строку данными newRow.CarID = 999; newRow.Color = "Purple"; newRow.Make = "BMW"; newRow.PetName = "Saku"; // Вставить новую строку dt.AddInventoryRow(newRow); // Добавить еще одну строку, используя перегруженный метод добавления dt.AddInventoryRow(777, "Yugo", "Green", "Zippy"); // Обновить базу данных dAdapt.Update(dt); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void AddRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) // Добавление записей { AutoLotDataSet.InventoryRow newRow = table.NewInventoryRow(); // Получение из таблицы новой строго типизированной строки newRow.CarID = 999; // Заполнение строки данными newRow.Color = "Purple"; newRow.Make = "BMW"; newRow.PetName = "Saku"; table.AddInventoryRow(newRow); // Вставка новой строки table.AddInventoryRow(888, "Yugo", "Green", "Zippy"); adapter.Update(table); // Обновление базы данных }
static void Main(string[] args) { AutoLotDataSet.InventoryDataTable table = new AutoLotDataSet.InventoryDataTable(); InventoryTableAdapter adapter = new InventoryTableAdapter(); AddRecords(table, adapter); table.Clear(); adapter.Fill(table); PrintInventory(table); Console.ReadLine(); }
private static void RemoveRow(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter, int n) { var rows = table.Rows; if ((n = ((AutoLotDataSet.InventoryRow)rows[rows.Count - n]).CarId) > 12) { WriteLine($"- remove row with CarId {n}"); AutoLotDataSet.InventoryRow row = table.FindByCarId(n); adapter.Delete(row.CarId, row.Make, row.Color, row.PetName); } }
private static void AddRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { AutoLotDataSet.InventoryRow newRow = table.NewInventoryRow(); newRow.Color = "Purple"; newRow.Make = "BMW"; newRow.PetName = "Saku"; table.AddInventoryRow(newRow); table.AddInventoryRow("Yugo", "Green", "Zippy"); adapter.Update(table); }
private static void ShowTable() { ForegroundColor = ConsoleColor.Yellow; WriteLine("=> Diaplay Inventory Data Using AutoLogDAL library version 3"); var table = new AutoLotDataSet.InventoryDataTable(); var adapter = new InventoryTableAdapter(); adapter.Fill(table); PrintInventory(table); }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable tb, InventoryTableAdapter dAdapt) { try { AutoLotDataSet.InventoryRow rowToDelete = tb.FindByCarID(991); dAdapt.Delete(rowToDelete.CarID, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); rowToDelete = tb.FindByCarID(887); dAdapt.Delete(rowToDelete.CarID, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void RemoveRecord(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { try { AutoLotDataSet.InventoryRow rowToDelete = table.FindByCarId(1); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); rowToDelete = table.FindByCarId(2); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); } catch (Exception ex) { WriteLine(ex.Message); } }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { try { Write("Enter ID of car to delete: "); string carID = ReadLine() ?? "0"; AutoLotDataSet.InventoryRow rowToDelete = table.FindByCarId(int.Parse(carID)); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); } catch (Exception ex) { WriteLine(ex.Message); } }
private static void AddRows() { ForegroundColor = ConsoleColor.Cyan; WriteLine("=> Add Two Rows Using AutoLogDAL library version 3"); var table = new AutoLotDataSet.InventoryDataTable(); var adapter = new InventoryTableAdapter(); adapter.Fill(table); AddRecords(table, adapter); table.Clear(); adapter.Fill(table); PrintInventory(table); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Strongly Typed DataSets *****\n"); // Caller creates the DataSet object. var table = new AutoLotDataSet.InventoryDataTable(); // Inform adapter of the Select command text and connection. var adapter = new InventoryTableAdapter(); // Fill our DataSet with a new table, named Inventory. adapter.Fill(table); PrintInventory(table); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("**********Work with Strongly Typed DataSet***********"); var table = new AutoLotDataSet.InventoryDataTable(); var adapter = new InventoryTableAdapter(); //AddRecords(table, adapter); adapter.Fill(table); RemoveRecords(table, adapter); adapter.Fill(table); PrintInventory(table); Console.ReadLine(); }
private static void DelRows() { ForegroundColor = ConsoleColor.DarkYellow; WriteLine("=> Delete Records Using AutoLogDAL library"); var table = new AutoLotDataSet.InventoryDataTable(); var adapter = new InventoryTableAdapter(); adapter.Fill(table); DelRecords(table, adapter); table.Clear(); adapter.Fill(table); PrintInventory(table); }
static void Main(string[] args) { Console.WriteLine("***** LINQ over DataSet *****\n"); // 获取包含AutoLot数据库中当期Inventory的强类型DataTable AutoLotDataSet dal = new AutoLotDataSet(); InventoryTableAdapter da = new InventoryTableAdapter(); AutoLotDataSet.InventoryDataTable data = da.GetData(); PrintAllCarIDs(data); ShowRedCars(data); BuildDataTableFromQuery(data); Console.ReadLine(); }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable tb, InventoryTableAdapter adapter) { try { Console.WriteLine("Enter carId what you want delete: "); int carIdToDelete = int.Parse(Console.ReadLine().ToString()); AutoLotDataSet.InventoryRow rowToDelete = tb.FindByCarId(carIdToDelete); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.PetName); adapter.Update(tb); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void RemoveRecords(AutoLotDataSet.InventoryDataTable table, InventoryTableAdapter adapter) { try { AutoLotDataSet.InventoryRow rowToDelete = table.FindByCarId(table.Last().CarId); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.Name); rowToDelete = table.FindByCarId(table.Last().CarId - 1); adapter.Delete(rowToDelete.CarId, rowToDelete.Make, rowToDelete.Color, rowToDelete.Name); adapter.Update(table); } catch (Exception ex) { WriteLine(ex.Message); } }
static void Main(string[] args) { WriteLine("**** LINQ over DataSet ****\n"); //Get a strongly typed DataTable containing the current Inventory // of the AutoLot Database AutoLotDataSet dal = new AutoLotDataSet(); InventoryTableAdapter tableAdapter = new InventoryTableAdapter(); AutoLotDataSet.InventoryDataTable data = tableAdapter.GetData(); //Invoke the methods that follow here! PrintAllCarIDs(data); ShowRedCars(data); ReadLine(); }
private static void BuildDataTableFromQuery(AutoLotDataSet.InventoryDataTable data) { var cars = from car in data.AsEnumerable() where car.Field <int>("CarId") > 5 select car; DataTable newTable = cars.CopyToDataTable(); // Использование этого результирующего набора для создания нового DataTable for (int currentRow = 0; currentRow < newTable.Rows.Count; currentRow++) { for (int currentColumn = 0; currentColumn < newTable.Columns.Count; currentColumn++) { Console.Write(newTable.Rows[currentRow][currentColumn].ToString().Trim() + "\t"); } } Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("****** LINQ over DataSet ******\n"); // Получить строго типизированный объект DataTable, содержащий // текущие данные таблицы Inventory из базы данных AutoLot AutoLotDataSet dal = new AutoLotDataSet(); InventoryTableAdapter da = new InventoryTableAdapter(); AutoLotDataSet.InventoryDataTable data = da.GetData(); PrintAllCarIDs(data); ShowBlackCars(data); BuildDataTableFromQuery(data); Console.ReadLine(); }
static void PrintInventory(AutoLotDataSet.InventoryDataTable dt) { for (int curCol = 0; curCol < dt.Columns.Count; curCol++) { Console.Write(dt.Columns[curCol].ColumnName + "\t"); } Console.WriteLine("\n-----------------------------"); for (int curRow = 0; curRow < dt.Rows.Count; curRow++) { for (int curCol = 0; curCol < dt.Columns.Count; curCol++) { Console.Write(dt.Rows[curRow][curCol].ToString() + "\t"); } Console.WriteLine(); } }
private static void UseEnumerable() { ForegroundColor = ConsoleColor.Yellow; WriteLine("=> Linq-Complatible DataTable"); AutoLotDataSet dal = new AutoLotDataSet(); InventoryTableAdapter adapter = new InventoryTableAdapter(); AutoLotDataSet.InventoryDataTable data = adapter.GetData(); PrintAllCarIDs(data); ShowBalckCars(data); ShowBlackSafety(data); BuildDataTableFromQuery(data); }
static void Main(string[] args) { AutoLotDataSet.InventoryDataTable table = new AutoLotDataSet.InventoryDataTable(); InventoryTableAdapter dAdapt = new InventoryTableAdapter(); AddRecords(table, dAdapt); table.Clear(); dAdapt.Fill(table); RemoveRecords(table, dAdapt); PrintInventory(table); CallStoreProc(); Console.ReadLine(); }