1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using MySql.Data.Common;
namespace Connection
{
class Program
{
static void Main(string[] args)
{
// Building a connection string
string cs = "server=localhost;user=admin;" +
"database=test;port=3306;password=admin";
try
{
// Creating a MySql connection
Console.WriteLine("Connecting to MySQL...");
MySqlConnection conn = new MySqlConnection(cs);
string[] stationName = { "blabla", "bloblo", "blublu" };
int i;
conn.Open();
for (i = 0; i < stationName.Length; i++)
{
MySqlCommand cmd = new MySqlCommand((@"CREATE TABLE IF NOT EXISTS `" + stationName[i] + @"` (`STN` int(6) NOT NULL,
`WBAN` int(5) NOT NULL,
`YEARMODA` int(8) NOT NULL,
`TEMP` double(4,1) NOT NULL,
`CountMeanTemp` int(2) NOT NULL,
`DEWP` double(4,1) NOT NULL,
`CountMeanDewPoint` int(2) NOT NULL,
`SLP` double(4,1) NOT NULL,
`CountSlp` int(2) NOT NULL,
`STP` double(4,1) NOT NULL,
`CountStp` int(2) NOT NULL,
`VISIB` double(3,1) NOT NULL,
`CountVisib` int(2) NOT NULL,
`WDSP` double(3,1) NOT NULL,
`CountWsdp` int(2) NOT NULL,
`MXSPD` double(3,1) NOT NULL,
`GUST` double(3,1) NOT NULL,
`MAX` double(4,1) NOT NULL,
`MIN` double(4,1) NOT NULL,
`PRCP` double(2,2) NOT NULL,
`SNDP` double(3,1) NOT NULL,
`FRSHTT` int(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1"), conn);
cmd.ExecuteNonQuery();
Console.WriteLine("table {0} created", stationName[i]);
}
Console.WriteLine("you're done!");
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
// A Console.ReadKey() statement so that to prevent
// the console window from closing
Console.ReadKey();
}
}
} |