SqlParameter does not allows Table name - other options without sql injection attack?

前端 未结 3 398
清酒与你
清酒与你 2020-11-30 11:01

I got a runtime error saying \"Must declare the table variable \"@parmTableName\". Meaning having table name as sql parameter in the sql-statement is not allow

3条回答
  •  悲&欢浪女
    2020-11-30 11:09

    (sqlAsk is string, right?) if it's right so let's try this:

    using(var dbCommand = dbConnection.CreateCommand())
    {
       sqlAsk = "";
       sqlAsk += " DELETE FROM  ";
       sqlAsk += " WHERE ImportedFlag = 'F' ";
    
       string table_name = "Your table name here";  //<- fill this as u need 
       sqlAsk = sqlAsk.Replace("", table_name); // it will replace  text to string table_name
    
       dbConnection.Open();
    
       rowAffected = dbCommand.ExecuteNonQuery();
    }
    

提交回复
热议问题