检查查询字符串是否传递给“string SqlCommand.CommandText”

M.B*_*lah 5 c# winforms

我的代码包含两个方法。

第一种方法是用于(插入、更新和删除),第二种方法是从数据库读取数据。

//Method to insert, update and delete data from database
public async Task ExcuteCommande(string stored_procedure, SqlParameter[] param)
{
    using (SqlCommand sqlcmd = new SqlCommand())
    {
        if (string.IsNullOrEmpty(stored_procedure))
        {
            return;
        }
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.CommandText = stored_procedure;
        sqlcmd.Connection = sqlconnection;
        if (param != null)
        {
            sqlcmd.Parameters.AddRange(param);
        }
        await sqlcmd.ExecuteNonQueryAsync().ConfigureAwait(false);
    }
}

//Method to read data from database
public async Task<DataTable> SelectData(string stored_procedure, SqlParameter[] param)
{
    using (SqlCommand sqlcmd = new SqlCommand())
    {
        if (string.IsNullOrEmpty(stored_procedure))
        {
            return null;
        }
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.CommandText = stored_procedure;
        sqlcmd.Connection = sqlconnection;
        if (param != null)
        {
            sqlcmd.Parameters.AddRange(param);
        }
        using (SqlDataAdapter da = new SqlDataAdapter(sqlcmd))
        {
            using (DataTable dt = new DataTable())
            {
                await Task.Run(() => da.Fill(dt)).ConfigureAwait(false);
                return dt;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这段代码下收到警告和绿线

`sqlcmd.CommandText = stored_procedure;`
Run Code Online (Sandbox Code Playgroud)

与此消息:

警告 CA2100 检查传递到“ExcuteCommande”中的“string SqlCommand.CommandText”的查询字符串是否接受任何用户输入。

处理此警告的最佳方法是什么?