首页 » .NET » C#连接嵌入式小型数据库firebird,操作数据

C#连接嵌入式小型数据库firebird,操作数据

原文 http://blog.csdn.net/u011511086/article/details/79174757

2018-01-27 02:00:24阅读(405)

怎么创建数据库请参考
http://blog.csdn.net/u011511086/article/details/79174680

C#測試firebird嵌入式數據庫demo地址下載
链接: https://pan.baidu.com/s/1eczOsu 密码: pc3m

此示例demo的csdn下载地址
http://download.csdn.net/download/u011511086/10226084

數據庫下載:
https://www.firebirdsql.org/en/firebird-2-5-8/

.NET驅動下載
https://www.firebirdsql.org/en/additional-downloads/

C#示例代碼
https://www.firebirdsql.org/en/net-examples-of-use/

项目bin目录
C#连接嵌入式小型数据库firebird,操作数据

using FirebirdSql.Data.FirebirdClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace FirebirdTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //這裡的fbembed的版本是2.5.8
            FbConnectionStringBuilder sb = new FbConnectionStringBuilder();
            sb.ServerType = FbServerType.Embedded;
            //SYSDBA
            sb.UserID = "SYSDBA";
            //masterkey
            sb.Password = "masterkey";
            sb.Database = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "") + "DB\\TEST.FDB";
            FbConnection connection1 = new FbConnection(sb.ToString());
            connection1.Open();
            //事務       
            FbTransaction tran = connection1.BeginTransaction();
            try
            {
                //插入
                FbCommand cmd2 = connection1.CreateCommand();
                cmd2.Transaction = tran;
                string sql2 = "INSERT INTO USERINFO (ID, NAME, SPASSWORD) VALUES (@id, @name, @password)";
                cmd2.CommandText = sql2;
                cmd2.Parameters.Add(new FbParameter("@id", Guid.NewGuid().ToString()));
                cmd2.Parameters.Add(new FbParameter("@name", "歐陽修0"));
                cmd2.Parameters.Add(new FbParameter("@password", "sdf56756"));
                int count = cmd2.ExecuteNonQuery();
                cmd2.Dispose();
                //修改
                FbCommand updateCmd = connection1.CreateCommand();
                updateCmd.Transaction = tran;
                string sql_update = "update USERINFO set  NAME='小萬1' where id='700A096E-5B28-7AF7-8D61-C3E0D0FF93FF'";
                updateCmd.CommandText = sql_update;
                int count_up = updateCmd.ExecuteNonQuery();
                updateCmd.Dispose();
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
            }
            //查询
            string sql = "select * from USERINFO";
            FbCommand cmd = new FbCommand(sql, connection1);
            FbDataAdapter dp = new FbDataAdapter(cmd);
            DataTable dt = new DataTable();
            dp.Fill(dt);
            dp.Dispose();
            cmd.Dispose();
            connection1.Close();
            connection1.Dispose();
        }
    }
}

报错解决:

C#连接嵌入式小型数据库firebird,操作数据

C#连接嵌入式小型数据库firebird,操作数据

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹