Esempio decisamente banale e poco edificante.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace VehicleRepairLab { public partial class frmVehicleRepairLab : Form { private DataSet ds; public frmVehicleRepairLab() { InitializeComponent(); } private void frmVehicleRepairLab_Load(object sender, EventArgs e) { CreateSchema(); } private void CreateSchema() { ds = new DataSet("VehiclesRepairs"); var vehicles = ds.Tables.Add("Vehicles"); vehicles.Columns.Add("VIN", typeof(string)); vehicles.Columns.Add("Make", typeof(string)); vehicles.Columns.Add("Model", typeof(string)); vehicles.Columns.Add("Year", typeof(int)); vehicles.PrimaryKey = new DataColumn[] { vehicles.Columns["VIN"] }; var repairs = ds.Tables.Add("Repairs"); var pk = repairs.Columns.Add("ID", typeof(int)); pk.AutoIncrement = true; pk.AutoIncrementSeed = -1; pk.AutoIncrementStep = -1; repairs.Columns.Add("VIN", typeof(string)); repairs.Columns.Add("Description", typeof(string)); repairs.Columns.Add("Cost", typeof(decimal)); repairs.PrimaryKey = new DataColumn[] { repairs.Columns["ID"] }; ds.Relations.Add( "vehicles_repairs", vehicles.Columns["VIN"], repairs.Columns["VIN"]); MessageBox.Show("Schema created!"); } } }
Nessun commento:
Posta un commento