public void Example6()
        {
            // Create and Open the Connection
            SqlConnection conn = new SqlConnection(
                "server=localhost;" +
                "database=ADONET;" +
                "Integrated Security=true;");

            // Create a DataAdapter for each of the tables we're filling
            SqlDataAdapter daCustomers = new SqlDataAdapter("SELECT * FROM CUSTOMER;", conn);

            // Create the Invoice DataAdapter
            SqlDataAdapter daInvoices = new SqlDataAdapter("SELECT * FROM INVOICE", conn);

            // Create the DataSet
            CustomerTDS typedDS = new CustomerTDS();

            // Use the DataAdapters to fill the DataSet
            daCustomers.Fill(typedDS, "Customer");
            daInvoices.Fill(typedDS, "Invoice");

            // Show the address and # of invoices for each customer
            foreach (CustomerTDS.CustomerRow custRow in typedDS.Customer)
            {
                Console.WriteLine(custRow.FullName);
                Console.WriteLine(custRow.Address);
                Console.WriteLine("{0}, {1}  {2}", custRow.City, custRow.State, custRow.Zip);
                Console.WriteLine("{0} (hm)", custRow.IsHomePhoneNull() ? "" : custRow.HomePhone);
                Console.WriteLine("{0} (bus)", custRow.IsBusinessPhoneNull() ? "" : custRow.BusinessPhone);
                Console.WriteLine("Invoices: " + custRow.GetChildRows("CustomerInvoice").Length);
                Console.WriteLine("");
            }
        }
        public void Example2()
        {
            // Create and Open the Connection
            SqlConnection conn = new SqlConnection(
                "server=localhost;" +
                "database=ADONET;" +
                "Integrated Security=true;");

            // Create a DataAdapter for each of the tables we're filling
            SqlDataAdapter daCustomers = new SqlDataAdapter("SELECT * FROM CUSTOMER;", conn);

            // Create the Invoice DataAdapter
            SqlDataAdapter daInvoices = new SqlDataAdapter("SELECT * FROM INVOICE", conn);

            // Create your blank DataSet
            CustomerTDS dataSet = new CustomerTDS();

            // Fill the DataSet with each DataAdapter
            daCustomers.Fill(dataSet, "Customers");
            daInvoices.Fill(dataSet, "Invoices");

            // Show the Customer Name
            Console.WriteLine(dataSet.Customer[0].FirstName);
            Console.WriteLine(dataSet.Customer[0].LastName);
            Console.WriteLine(dataSet.Customer[0].HomePhone);

            // This will not compile because InvoiceNumber expects an integer
            //dataSet.Invoice[0].InvoiceNumber = "12345";
        }
示例#3
0
        public override DataSet Clone()
        {
            CustomerTDS cln = ((CustomerTDS)(base.Clone()));

            cln.InitVars();
            return(cln);
        }