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(); } } }
C#中使用嵌入式firebird数据库
最新推荐文章于 2018-10-09 18:35:54 发布