Exemplo n.º 1
0
        public static void Demo4()
        {
            ExampleDb nds = new ExampleDb();

            ExampleDbTableAdapters.CustomersTableAdapter ndsAdapter = new ExampleDbTableAdapters.CustomersTableAdapter();
            ndsAdapter.Fill(nds.Customers);

            ExampleDbTableAdapters.OrdersTableAdapter ordTblApt = new ExampleDbTableAdapters.OrdersTableAdapter();
            ordTblApt.Fill(nds.Orders);

            //通过Customers表中的CustomerID(主键)查找Orders表中对应的数据
            ExampleDb.CustomersRow cusRow1   = (ExampleDb.CustomersRow)nds.Customers.Rows.Find(1);
            ExampleDb.CustomersRow cusRow2   = nds.Customers.FindByCustomerID(1);
            StringBuilder          sbBuilder = new StringBuilder();

            foreach (var rowResult in cusRow1.GetOrdersRows())
            {
                sbBuilder.Append(rowResult.OrderID + " " + rowResult.OrderDate + "  " + rowResult.CustomerID + Environment.NewLine);
            }

            foreach (var rowResult in cusRow2.GetOrdersRows())
            {
                sbBuilder.Append(rowResult.OrderID + " " + rowResult.OrderDate + "  " + rowResult.CustomerID + Environment.NewLine);
            }

            //通过Orders表中的CustomerID(外键)查找Customers表中的数据
            ExampleDb.OrdersRow ordRowResult = (ExampleDb.OrdersRow)nds.Orders.Rows.Find(1);

            sbBuilder.Append(ordRowResult.CustomerID + Environment.NewLine);
            sbBuilder.Append(ordRowResult.OrderDate + Environment.NewLine);

            //修改数据
            ExampleDb.CustomersRow cr = ordRowResult.CustomersRow;
            sbBuilder.Append(cr.CustomerID);
            sbBuilder.Append(cr.CompanyName);
            cr.CompanyName = "name19:44";
            ndsAdapter.Update(cr);
            Console.WriteLine(cr.CompanyName);

            //修改数据
            ExampleDb.CustomersRow cusRow = nds.Customers.FindByCustomerID(1);
            cusRow.CompanyName = "MyCompanyName";
            ndsAdapter.Update(cusRow);
            Console.WriteLine(cusRow.CompanyName);

            //添加一行数据
            ExampleDb.CustomersRow newRow = nds.Customers.AddCustomersRow("aMyName");
            ndsAdapter.Update(newRow);

            //删除一行数据
            ndsAdapter.Delete(4, "aMyName");

            MessageBox.Show(sbBuilder.ToString());
        }
Exemplo n.º 2
0
        private static void Demo3()
        {
            ExampleDb nds = new ExampleDb();

            ExampleDbTableAdapters.OrdersTableAdapter ordTblApt = new ExampleDbTableAdapters.OrdersTableAdapter();
            ordTblApt.Fill(nds.Orders);

            StringBuilder sbBuilder = new StringBuilder();

            foreach (ExampleDb.OrdersRow ordRow in nds.Orders.Rows)
            {
                sbBuilder.Append(ordRow.OrderID + "  " + ordRow.CustomerID + "  " + ordRow.OrderDate + Environment.NewLine);
            }
            MessageBox.Show(sbBuilder.ToString());
        }
Exemplo n.º 3
0
        private static void Demo2()
        {
            ExampleDb nds = new ExampleDb();

            ExampleDbTableAdapters.CustomersTableAdapter ndsAdapter = new ExampleDbTableAdapters.CustomersTableAdapter();
            ndsAdapter.Fill(nds.Customers);

            StringBuilder sbBuilder = new StringBuilder();

            foreach (ExampleDb.CustomersRow ct in nds.Customers.Rows)
            {
                sbBuilder.Append(ct.CustomerID + "  " + ct.CompanyName + Environment.NewLine);
            }

            DataRow row = nds.Customers.Rows.Find(1);

            sbBuilder.Append(row["CompanyName"]);
            MessageBox.Show(sbBuilder.ToString());
        }
Exemplo n.º 4
0
 public CategoriesController(ExampleDb context)
 {
     _context = context;
 }
Exemplo n.º 5
0
 public ProductsController(ExampleDb context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public orderHistoriesController(ExampleDb context)
 {
     _context = context;
 }
Exemplo n.º 7
0
 public RegisterController(ExampleDb context)
 {
 }