本文主要是介绍C#连接嵌入式小型数据库firebird,操作数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
怎么创建数据库请参考
http://blog.csdn.net/u011511086/article/details/79174680
C#測試firebird嵌入式數據庫demo地址下載
https://pan.baidu.com/s/1dFZvNtZ
此示例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目录
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.8FbConnectionStringBuilder sb = new FbConnectionStringBuilder();sb.ServerType = FbServerType.Embedded;//SYSDBAsb.UserID = "SYSDBA";//masterkeysb.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,操作数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!