Exemple #1
0
        private void ShowSQLConnectionStringBuilder()
        {
            ConnectionStringCreatorGUI.SqlConnectionString initialConnStr;

            try
            {
                initialConnStr = new ConnectionStringCreatorGUI.SqlConnectionString(Model.ConnectionString);
            }
            catch (Exception)
            {
                initialConnStr = new ConnectionStringCreatorGUI.SqlConnectionString();
            }

            Window win = new ConnectionStringCreatorGUI.ConnectionStringBuilderWindow(initialConnStr, returnConnBuilder =>
            {
                Model.ConnectionString = returnConnBuilder.ToString();
                try
                {
                    AdhocDataAccess adhd = new AdhocDataAccess(Model.ConnectionString);

                    adhd.TestConnection();
                }
                catch (Exception e)
                {
                    MessageBox.Show("The connection is not valid, Check Server, Database and credentials: " + Environment.NewLine + Environment.NewLine + e.Message);
                }
            });

            win.Show();
        }
        private static void CreateTablesInDB()
        {
            AdhocDataAccess adhd = new AdhocDataAccess(Connection());

            string sql = @"

if not exists(SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'Person') exec('CREATE SCHEMA Person');

if exists (select 1 from INFORMATION_SCHEMA.tables where TABLE_NAME = 'AnotherTable' and TABLE_SCHEMA = 'Person')
	drop table Person.AnotherTable;

if exists (select 1 from INFORMATION_SCHEMA.tables where TABLE_NAME = 'NewPerson' and TABLE_SCHEMA = 'Person')
	drop table Person.NewPerson;

if exists (select 1 from INFORMATION_SCHEMA.tables where TABLE_NAME = 'Person' and TABLE_SCHEMA = 'Person')
	drop table Person.Person;

if exists (select 1 from INFORMATION_SCHEMA.tables where TABLE_NAME = 'Address' and TABLE_SCHEMA = 'Person')
	drop table Person.Address;
	
	
	
create table Person.NewPerson(
	NewPersonId int identity(1, 1) primary key,
	Name varchar(500) not null,
	BitColumn bit not null, 
	DecimalColumn decimal(10, 4) not null,
	BigintColumn bigint not null, 
	VarcharMaxColumn varchar(max)  not null,
	FloatColumn float not null,
	DateTime2Column datetime2 not null,
	DateTimeColumn datetime not null,
	NCharFiveColumn nchar(5) not null,
	DateColumn date not null, 
	TimeColumn time not null,
	SmallIntColumn smallint not null,
	SmallDateTimeColumn smalldatetime not null,
	SmallMoneyColumn smallmoney  not null
);



create table Person.Address(
	AddressID int identity(1, 1) primary key,
    AddressLine1 varchar(500) not null, 
    AddressLine2 varchar(500), 
    City varchar(500) not null, 
    StateProvinceID int not null, 
    PostalCode varchar(500) not null, 
    rowguid uniqueidentifier, 
    ModifiedDate datetime
);


create table Person.Person(
	NewPersonId int identity(1, 1) primary key,
	Name varchar(500) not null,
	BitColumn bit not null, 
	DecimalColumn decimal(10, 4) not null
);

create table Person.AnotherTable(
	NewPersonId int foreign key references Person.NewPerson(NewPersonId) not null,
	AnotherColumn char(1),
    ThirdColumn char(1) not null
);";

            adhd.ExecuteNonQuery(sql);
        }