//--------------------------------------------------------------------- private void TestTableAdapter1() { //<Snippet7> NorthwindDataSetTableAdapters.CustomersTableAdapter tableAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); tableAdapter.FillByCity(northwindDataSet.Customers, "Seattle"); //</Snippet7> //<Snippet8> SqlConnection sqlConnection1 = new SqlConnection("Your Connection String"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "SELECT * FROM Customers"; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); reader = cmd.ExecuteReader(); // Data is accessible through the DataReader object here. sqlConnection1.Close(); //</Snippet8> }
//--------------------------------------------------------------------- void Test() { NorthwindDataSet northwindDataSet1 = new NorthwindDataSet(); //<Snippet3> NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter1; customersTableAdapter1 = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); //</Snippet3> //<Snippet4> customersTableAdapter1.Fill(northwindDataSet1.Customers); //</Snippet4> //<Snippet5> NorthwindDataSet.CustomersDataTable newCustomersTable; newCustomersTable = customersTableAdapter1.GetData(); //</Snippet5> //<Snippet6> NorthwindDataSetTableAdapters.QueriesTableAdapter scalarQueriesTableAdapter; scalarQueriesTableAdapter = new NorthwindDataSetTableAdapters.QueriesTableAdapter(); int returnValue; returnValue = (int)scalarQueriesTableAdapter.CustomerCount(); //</Snippet6> }
//--------------------------------------------------------------------- private void TestTableAdapter3() { //<Snippet11> NorthwindDataSetTableAdapters.CustomersTableAdapter tableAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); int rowsAffected = tableAdapter.UpdateContactTitle("Sales Manager", "ALFKI"); //</Snippet11> }
//--------------------------------------------------------------------- private void TestTableAdapter2() { //<Snippet9> NorthwindDataSetTableAdapters.CustomersTableAdapter tableAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); int returnValue = (int)tableAdapter.GetCustomerCount(); //</Snippet9> }
//--------------------------------------------------------------------- void Test2() { //<Snippet7> NorthwindDataSet northwindDataSet = new NorthwindDataSet(); NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); customersTableAdapter.Fill(northwindDataSet.Customers); //</Snippet7> }
private void ButtonGetCustomers_Click(object sender, EventArgs e) { NorthwindDataSet NorthwindDataset1 = new NorthwindDataSet(); NorthwindDataSetTableAdapters.CustomersTableAdapter CustomersTableAdapter1 = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); CustomersTableAdapter1.Fill(NorthwindDataset1.Customers); foreach (NorthwindDataSet.CustomersRow NWCustomer in NorthwindDataset1.Customers.Rows) { ListBoxCustomers.Items.Add(NWCustomer.CompanyName); } }
private void GetCustomersButton_Click(object sender, EventArgs e) { NorthwindDataSet northwindDataSet1 = new NorthwindDataSet(); NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter1 = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); customersTableAdapter1.Fill(northwindDataSet1.Customers); foreach (NorthwindDataSet.CustomersRow NWCustomer in northwindDataSet1.Customers.Rows) { CustomersListBox.Items.Add(NWCustomer.CompanyName); } }
public UserControlTabsGrid() { InitializeComponent(); ds = new NorthwindDataSet(); NorthwindDataSetTableAdapters.CustomersTableAdapter customerAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter(); //Populate adapter customerAdapter.Fill(ds.Customers); //Bind adapter to datagrid dataGrid1.ItemsSource = ds.Customers.DefaultView; }
public ViewModel() { // populate the data set var dataSet = new NorthwindDataSet(); using (var customersAdp = new NorthwindDataSetTableAdapters.CustomersTableAdapter()) using (var ordersAdp = new NorthwindDataSetTableAdapters.OrdersTableAdapter()) { customersAdp.Fill(dataSet.Customers); ordersAdp.Fill(dataSet.Orders); } // populate your domain objects var customers = dataSet.Customers.ToArray().Select(cust => new Customer { Name = cust.Company_Name, Orders = cust.GetOrdersRows().Select(order => new Order { Id = order.Order_ID }) }); this.Customers = customers; // build the report StringBuilder report = new StringBuilder(); string formatString = "{0,-30}|{1}"; report.Append(string.Format(formatString, "Name", "Order Ids")); report.Append(Environment.NewLine); Customers.ToList().ForEach(cust => report.AppendLine(string.Format( formatString, cust.Name, string.Join(",", cust.Orders.Select(o => o.Id).ToArray())) )); // display the report Report = report.ToString(); }