Created
July 27, 2015 15:19
-
-
Save kowill/1335ef4927e1f8476094 to your computer and use it in GitHub Desktop.
C#でのFireBird接続。(FirebirdClient)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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