Insert Firebird Database C#

房东的猫 提交于 2019-12-02 13:14:53

问题


FbCommand fbCmm = 
      new FbCommand("INSERT INTO PRODUTO
                   (CODIGO,EAN,DESCRICAO,VAL_PRODUTO,VAL_CUSTO,CAT_PRECO)" 
                   + "Values (@txt_codigo.Text, @txt_ean, @txt_descricao,
                   @txt_valPro, @txt_valCus, @txt_catPre)", ConexaoFirebird.Conexao);

What's wrong with that sentence? I did a open connection in other class - ConexaoFirebird.Conexao();


回答1:


You're executing a parameterized query without providing values for those parameters. See the documentation:

FbCommand cmd = new FbCommand("insert into t1(id, text) values (@id, @text);");
cmd.CommandType = CommandType.Text;

cmd.Parameters.Add("@id", 123);
cmd.Parameters.Add("@text", "my string");

cmd.ExecuteNonQuery();

Here they bind the values 123 and "my string" to the parameters named id and text respectively.

Also note that parameter names are generally rescticted to alphanumeric, so txt_codigo.Text isn't likely going to work.




回答2:


You should use quote for decimal, string field types, your statement is correct but not clear, you can create clear sql text with sql command builder or you can use Command object of your connection.



来源:https://stackoverflow.com/questions/43982269/insert-firebird-database-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!