1. 下载firebird
http://www.firebirdsql.org/en/server-packages/笔者选的是2.5.2
2. 解压,进入bin目录,install_super.bat
3. 我的电脑右键->管理->服务,将firebird的服务置成手动
4. 可选,下载一个firebird的client,笔者选的是FlameRobin还挺好用的
至此,可以试试firebird了,可以使用firebird/bin/isql,
CREATE DATABASE 'firstdb.gdb' USER 'sysdba' PASSWORD 'masterkey';
然后使用客户端去操作一下,比较标准的sql语言
5. 下载.net的连接firebird的库, .net provider
http://www.firebirdsql.org/en/net-provider/,请注意与你工程的.net版本匹配.
6. 将dll引用到工程中,右键点击右侧引用,添加...
7.
class Helper
{
private static Helper helper = new Helper();
private FbConnection cn ;
private Helper(){
FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
cs.DataSource = "127.0.0.1";
cs.Database = @"C:\HOUSENUMBER.FDB";
cs.UserID = "sysdba";
cs.Password = "masterkey";
//Console.WriteLine(Directory.GetFiles(@"../").ToString());
//cs.Dialect = 1;
cn = new FbConnection();
cn.ConnectionString = cs.ToString();
cn.Open();
}
public static Helper getInstance()
{
if(helper == null){
helper = new Helper();
}
return helper;
}
public void destroy()
{
if (cn != null)
{
cn.Close();
}
}
public void delete(int areaNo, int buildingNumber, String roomName)
{
FbCommand cmd = cn.CreateCommand();
String sql = "delete from ROOM where AREANO = " + areaNo + " and BUILDINGNUMBER = " + buildingNumber + " and NAME = '" + roomName+"'";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
public void add(RoomBean bean)
{
String sql ="INSERT INTO ROOM (NAME, BUILDINGNUMBER, FLOOR, ACTUALAREA, PUBLICAREA, TOTALAREA, PUBLICRATIO, UNDERNUMBER, UNDERNAME, UNDERFLOOR,"+
"UNDERACTUAL, UNDERPUBLIC, UNDERTOTAL, ISRESERVED, ISTOKEN, BUILDINGLEVEL, AREANO)"
+ "VALUES ('" +
bean.getName() + "', " +
bean.getBuildingNumber() + ", " +
bean.getFloor()+ ", " +
bean.getActualArea()+ ", " +
bean.getPublicArea()+", " +
bean.getTotalArea()+ ", " +
bean.getPublicRatio()+ ", '" +
bean.getUnderNumber() + "', '" +
bean.getUnderName() + "', " +
bean.getUnderFloor() + ", " +
bean.getUnderActual()+ ", " +
bean.getUnderPublic() + ", " +
bean.getUnderTotal() + ", " +
bean.getIsReserved()+ ", " +
bean.getIsToken()+ ", " +
bean.getBuildingLevel()+ ", " +
bean.getAreaNo() + ")";
FbCommand cmd = cn.CreateCommand();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
笔者写的一些简单例子