How to pass a table as parameter to MySqlCommand?

后端 未结 2 511
时光取名叫无心
时光取名叫无心 2020-12-02 02:37

I am creating a method to select the id from any table by passing a search field.

private int SelectId(string tabela, string campo, string valor)
{
    int i         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 02:55

    Most databases won't let you specify table or column names via parameters. Parameters are meant to be for values. If you really, really need this to be dynamic, you should validate the input (it should be a known table name, with known column names within that table) and then include that in the SQL.

提交回复
热议问题