程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#中使用嵌入式firebird數據庫

C#中使用嵌入式firebird數據庫

編輯:C#入門知識

 

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人生。。。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved