c#向firebird数据库添加数据 [英] c# add data to firebird database

查看:110
本文介绍了c#向firebird数据库添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有用于将新数据传递到Database(firebird)的代码:

There is code that I use to pass new data to Database (firebird):

FbConnection fbCon = new FbConnection(csb.ToString());
FbDataAdapter fbDAdapter = new FbDataAdapter("SELECT ID,name,score FROM players",fbCon);
FbCommandBuilder Cmd = new FbCommandBuilder(fbDAdapter);
DataSet DSet = new DataSet();
fbDAdapter.Fill(DSet);
DataRow rw = DSet.Tables[0].NewRow();
rw["ID"] = zID + 1;
rw["name"] = var;
rw["score"] = score;
DSet.Tables[0].Rows.Add(rw);
fbDAdapter.Update(DSet);

也许你可以建议更好的算法,或者这是很好吗?

Maybe you can suggest better algorithm, or this is pretty good?

推荐答案

这种方式是OK的,你使用一个命令构建器做很多工作,你可以简单地将上述代码转换为insert命令直接执行对数据库表:

This way is OK, you are using a command builder that do a lot of work for, you can simply translate the above code into an insert command to execute directly on the database table :

  FbConnection fbCon = new FbConnection(csb.ToString());
  FbCommand fbCom = new FbCommand("INSERT INTO players(ID,name,score) VALUES (@id,@name,@score)", fbCon);
  fbCom.Parameters.AddWithValue("id", zID + 1);
  fbCom.Parameters.AddWithValue("name", var);
  fbCom.Parameters.AddWithValue("score", score);
  fbCom.ExecuteNonQuery();

这样,避免了命令构建器并将数据加载到Datatable中,应该会更快。 ..

In this way you avoid the command builder and loading the data into the Datatable, should be quite faster ...

这篇关于c#向firebird数据库添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆