Skip to content

Instantly share code, notes, and snippets.

@kowill kowill/program.cs
Created Jul 27, 2015

Embed
What would you like to do?
C#でのFireBird接続。(FirebirdClient)
using FirebirdSql.Data.FirebirdClient;
using System.Data;
namespace FirebirdTest
{
class Program
{
static void Main(string[] args)
{
var connectionBuilder = new FbConnectionStringBuilder();
connectionBuilder.DataSource = "localhost";
connectionBuilder.Database = @"D:\Hoge.fdb";
connectionBuilder.Charset = FbCharset.Utf8.ToString();
connectionBuilder.UserID = "SYSDBA";
connectionBuilder.Password = "masterkey";
connectionBuilder.ServerType = FbServerType.Embedded;
FbConnection.CreateDatabase(connectionBuilder.ConnectionString);
using (var connection = new FbConnection(connectionBuilder.ConnectionString))
using (var command = connection.CreateCommand())
{
try
{
connection.Open();
command.CommandText = @"create table Test (id int, name varchar(50), primary key (id))";
command.ExecuteNonQuery();
command.CommandText = @"select * from rdb$relations where rdb$view_blr is null and (rdb$system_flag is null or rdb$system_flag = 0)";
var dt1 = new DataTable();
dt1.Load(command.ExecuteReader());
command.CommandText = @"select * from rdb$indices where (rdb$system_flag is null or rdb$system_flag = 0)";
var dt2 = new DataTable();
dt2.Load(command.ExecuteReader());
command.CommandText = @"insert into Test values (1, 'Hoge')";
command.ExecuteNonQuery();
command.CommandText = @"insert into Test values (2, 'HogeHoge')";
command.ExecuteNonQuery();
command.CommandText = @"insert into Test values (3, 'あいうえお')";
command.ExecuteNonQuery();
command.CommandText = @"select * from test where id = @id";
command.Parameters.Add("@id", 3);
var dt3 = new DataTable();
dt3.Load(command.ExecuteReader());
}
finally
{
connection.Close();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.