using System;
using System.Collections.Generic;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
namespace CreateDB
{
class Program
{
static void Main(string[] args)
{
FbConnection.CreateDatabase(GetConnectionString());
using (FbConnection conn = new FbConnection(GetConnectionString()))
{
conn.Open();
using (FbCommand createTable = conn.CreateCommand())
{
createTable.CommandText = "create table test (id int, word varchar(20) character set win1250)";
createTable.ExecuteNonQuery();
}
using (FbCommand insertData = conn.CreateCommand())
{
insertData.CommandText = "insert into test values (@id, @word)";
for (int i = 0; i < 10; i++)
{
insertData.Parameters.Clear();
insertData.Parameters.Add("@id", FbDbType.Integer).Value = i;
insertData.Parameters.Add("@word", FbDbType.VarChar, 20).Value = GetWord(i);
insertData.ExecuteNonQuery();
}
}
}
}
static string GetConnectionString()
{
FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
cs.Database = "test.fdb";
cs.UserID = "SYSDBA";
cs.Password = "masterkey";
cs.Charset = "UTF8";
cs.ServerType = FbServerType.Embedded;
return cs.ToString();
}
static string GetWord(int i)
{
StringBuilder sb = new StringBuilder(i);
for (int j = 0; j < i; j++)
{
sb.Append(i);
}
return sb.ToString();
}
}
}
李信的Crazy Coding人生。。。