c# add data to firebird database
10,443
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();
In this way you avoid the command builder and loading the data into the Datatable, should be quite faster ...
Author by
Bublik
Updated on June 04, 2022Comments
-
Bublik almost 2 years
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?